Skip to content

Commit 4de99a2

Browse files
committed
Added dependencies report in output.json
1 parent 956c34d commit 4de99a2

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

docs/GUIDE.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ The example below is available [here](../tests/test_resources/expected_output.js
2727
"n_c": 3,
2828
"nbm": 3,
2929
"analysis": "The code is under commented. Low abstract component, few interfaces. ",
30+
"dependencies": [
31+
"UIKit(1)",
32+
"FoundationFramework(1)"
33+
],
3034
"not": 0,
3135
"fan_in": 1,
3236
"fan_out": 2,
@@ -49,6 +53,9 @@ The example below is available [here](../tests/test_resources/expected_output.js
4953
"n_c": 1,
5054
"nbm": 1,
5155
"analysis": "The code is over commented. ",
56+
"dependencies": [
57+
"XCTest(1)"
58+
],
5259
"not": 1
5360
}
5461
},
@@ -89,7 +96,7 @@ The example below is available [here](../tests/test_resources/expected_output.js
8996
}
9097
```
9198

92-
Legend:
99+
KPIs legend:
93100

94101
| Key | Metric | Description |
95102
|:---------:|:--------------------------------:|:---------------------------------------------------------------------------------------------------:|
@@ -106,15 +113,24 @@ Legend:
106113
| `nbm` | Number of methods | Number of `func` (computed `var` excluded) |
107114
| `not` | Number of tests | Number of methods in test frameworks starting with `test` |
108115

116+
In addition:
117+
118+
| Key | Description |
119+
|:--------------:|:--------------------:|
120+
| `analysis` | Code metrics analysis on the code regarding percentage of comments and components coupling |
121+
| `dependencies` | List of internal and external dependencies, with number of imports |
122+
123+
109124
## Graphs
110125

111126
The `--generate-graphs` option will output the following reports:
112127

113128
| Components coupling |
114129
|:-----------:|
115130
| ![Dependency graph](assets/dependency_graph.jpg) |
116-
| Dependency graph |
131+
| Dependency graph, with number of imports of _destination_ from _origin_ . |
117132
| ![Distance from main sequence](assets/deviation_from_the_main_sequence.jpg) |
133+
| Distance of a library from the ideal domain. |
118134

119135
| Code distribution |
120136
|:-----------:|

swift_code_metrics/_analyzer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __framework_analysis(self, framework):
5353
n_a = framework.number_of_interfaces
5454
n_c = framework.number_of_concrete_data_structures
5555
nbm = framework.number_of_methods
56+
dependencies = list(map(lambda f: f[0].name + '(' + str(f[1]) + ')', framework.imports.items()))
5657
n_of_tests = framework.number_of_tests
5758

5859
# Non-test framework analysis
@@ -76,6 +77,7 @@ def __framework_analysis(self, framework):
7677
"n_c": n_c,
7778
"nbm": nbm,
7879
"analysis": analysis,
80+
"dependencies": dependencies,
7981
"not": n_of_tests
8082
}
8183

@@ -111,7 +113,8 @@ def __append_dependency(self, swift_file, is_in_test_path):
111113
framework.number_of_concrete_data_structures += len(swift_file.structs + swift_file.classes)
112114
framework.number_of_methods += len(swift_file.methods)
113115
framework.number_of_tests += len(swift_file.tests)
114-
framework.is_test_framework = is_in_test_path # This cover the scenario where a test framework might contain no tests
116+
# This cover the scenario where a test framework might contain no tests
117+
framework.is_test_framework = is_in_test_path
115118

116119
for f in swift_file.imports:
117120
imported_framework = self.__get_or_create_framework(f)

swift_code_metrics/_graphics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def bar_plot(self, title, data):
2424
def pie_plot(self, title, sizes, labels, legend):
2525
plt.title(title)
2626
patches, texts, _ = plt.pie(sizes, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
27-
plt.legend(patches, legend, loc="best")
27+
plt.legend(patches, legend, loc='lower left')
2828
plt.tight_layout()
2929
plt.axis('equal')
3030

tests/test_resources/expected_output.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"n_c": 3,
1010
"nbm": 3,
1111
"analysis": "The code is under commented. Low abstract component, few interfaces. ",
12+
"dependencies": [
13+
"UIKit(1)",
14+
"FoundationFramework(1)"
15+
],
1216
"not": 0,
1317
"fan_in": 1,
1418
"fan_out": 2,
@@ -26,6 +30,9 @@
2630
"n_c": 2,
2731
"nbm": 3,
2832
"analysis": "Zone of Uselessness. Maximally abstract with few or no dependents - potentially useless. This component is high likely a leftover that should be removed.",
33+
"dependencies": [
34+
"Foundation(2)"
35+
],
2936
"not": 0,
3037
"fan_in": 1,
3138
"fan_out": 2,
@@ -43,6 +50,10 @@
4350
"n_c": 2,
4451
"nbm": 4,
4552
"analysis": "Highly unstable component (lack of dependents, easy to change, irresponsible) Low abstract component, few interfaces. ",
53+
"dependencies": [
54+
"UIKit(2)",
55+
"BusinessLogic(1)"
56+
],
4657
"not": 0,
4758
"fan_in": 0,
4859
"fan_out": 3,
@@ -62,6 +73,9 @@
6273
"n_c": 1,
6374
"nbm": 1,
6475
"analysis": "The code is over commented. ",
76+
"dependencies": [
77+
"XCTest(1)"
78+
],
6579
"not": 1
6680
}
6781
},
@@ -74,6 +88,10 @@
7488
"n_c": 2,
7589
"nbm": 5,
7690
"analysis": "",
91+
"dependencies": [
92+
"XCTest(2)",
93+
"Foundation(1)"
94+
],
7795
"not": 3
7896
}
7997
},
@@ -86,6 +104,9 @@
86104
"n_c": 1,
87105
"nbm": 1,
88106
"analysis": "The code is over commented. ",
107+
"dependencies": [
108+
"XCTest(1)"
109+
],
89110
"not": 1
90111
}
91112
}

0 commit comments

Comments
 (0)