Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cyclomatic complexity to function-summary #1685

Merged
merged 2 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion slither/core/declarations/function_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from slither.core.children.child_contract import ChildContract
from slither.core.children.child_inheritance import ChildInheritance
from slither.core.declarations import Function
from slither.utils.code_complexity import compute_cyclomatic_complexity


# pylint: disable=import-outside-toplevel,too-many-instance-attributes,too-many-statements,too-many-lines
Expand Down Expand Up @@ -73,7 +74,7 @@ def functions_shadowed(self) -> List["Function"]:

def get_summary(
self,
) -> Tuple[str, str, str, List[str], List[str], List[str], List[str], List[str]]:
) -> Tuple[str, str, str, List[str], List[str], List[str], List[str], List[str], int]:
"""
Return the function summary
Returns:
Expand All @@ -89,6 +90,7 @@ def get_summary(
[str(x) for x in self.state_variables_written],
[str(x) for x in self.internal_calls],
[str(x) for x in self.external_calls_as_expressions],
compute_cyclomatic_complexity(self),
)

# endregion
Expand Down
17 changes: 16 additions & 1 deletion slither/printers/summary/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def output(self, _filename): # pylint: disable=too-many-locals
"Write",
"Internal Calls",
"External Calls",
"Cyclomatic Complexity",
]
)
for (
Expand All @@ -59,6 +60,7 @@ def output(self, _filename): # pylint: disable=too-many-locals
write,
internal_calls,
external_calls,
cyclomatic_complexity,
) in func_summaries:
read = self._convert(sorted(read))
write = self._convert(sorted(write))
Expand All @@ -73,6 +75,7 @@ def output(self, _filename): # pylint: disable=too-many-locals
write,
internal_calls,
external_calls,
cyclomatic_complexity,
]
)
txt += "\n \n" + str(table)
Expand All @@ -84,6 +87,7 @@ def output(self, _filename): # pylint: disable=too-many-locals
"Write",
"Internal Calls",
"External Calls",
"Cyclomatic Complexity",
]
)
for (
Expand All @@ -95,12 +99,23 @@ def output(self, _filename): # pylint: disable=too-many-locals
write,
internal_calls,
external_calls,
cyclomatic_complexity,
) in modif_summaries:
read = self._convert(sorted(read))
write = self._convert(sorted(write))
internal_calls = self._convert(sorted(internal_calls))
external_calls = self._convert(sorted(external_calls))
table.add_row([f_name, visi, read, write, internal_calls, external_calls])
table.add_row(
[
f_name,
visi,
read,
write,
internal_calls,
external_calls,
cyclomatic_complexity,
]
)
txt += "\n\n" + str(table)
txt += "\n"
self.info(txt)
Expand Down