Skip to content

Commit 2a6699e

Browse files
committed
Added improved warnings on exceptional cases when inspecting instability and abstractness
1 parent b73608b commit 2a6699e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

swift_code_metrics/_metrics.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from ._helpers import AnalyzerHelpers
22
from functional import seq
3-
3+
from warnings import warn
44

55
class Metrics:
66

@@ -29,7 +29,11 @@ def instability(framework, frameworks):
2929
"""
3030
fan_in = Metrics.fan_in(framework, frameworks)
3131
fan_out = Metrics.fan_out(framework)
32-
return fan_out / (fan_in + fan_out)
32+
sum_in_out = fan_in + fan_out
33+
if sum_in_out == 0:
34+
warn(f'{framework.name} is not linked with the rest of the project.', Warning)
35+
return 0
36+
return fan_out / sum_in_out
3337

3438
@staticmethod
3539
def abstractness(framework):
@@ -41,7 +45,7 @@ def abstractness(framework):
4145
:return: The abstractness value (double)
4246
"""
4347
if framework.number_of_concrete_data_structures == 0:
44-
# This is an external dependency build as source
48+
warn(f'{framework.name} is an external dependency.', Warning)
4549
return 0
4650
else:
4751
return framework.number_of_interfaces / framework.number_of_concrete_data_structures

0 commit comments

Comments
 (0)