diff --git a/slither/core/declarations/function_contract.py b/slither/core/declarations/function_contract.py index 19456bbead..01077353b1 100644 --- a/slither/core/declarations/function_contract.py +++ b/slither/core/declarations/function_contract.py @@ -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 @@ -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: @@ -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 diff --git a/slither/printers/summary/function.py b/slither/printers/summary/function.py index b9353ce252..7f1633865a 100644 --- a/slither/printers/summary/function.py +++ b/slither/printers/summary/function.py @@ -48,6 +48,7 @@ def output(self, _filename): # pylint: disable=too-many-locals "Write", "Internal Calls", "External Calls", + "Cyclomatic Complexity", ] ) for ( @@ -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)) @@ -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) @@ -84,6 +87,7 @@ def output(self, _filename): # pylint: disable=too-many-locals "Write", "Internal Calls", "External Calls", + "Cyclomatic Complexity", ] ) for ( @@ -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)