PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

Generic/CyclomaticComplexity: improve error message

Open rodrigoprimo opened this issue 1 year ago • 2 comments

Is your feature request related to a problem?

Both the warning and the error message displayed by the Generic.Metrics.CyclomaticComplexity sniff could be improved if they included the name of the function that caused the error.

Describe the solution you'd like

Currently, the sniff displays the following error messages:

  72 | WARNING | Function's cyclomatic complexity (20) exceeds 10; consider refactoring the function
 118 | ERROR   | Function's cyclomatic complexity (21) exceeds allowed maximum of 20

I'm suggesting we update them to something like (note that I also added "the" before "allowed maximum"):

  72 | WARNING | Function complexityTwenty()'s cyclomatic complexity (20) exceeds 10; consider refactoring the function
 118 | ERROR   | Function complexityTwentyOne()'s cyclomatic complexity (21) exceeds allowed maximum of 20

Additional context (optional)

Below there are links to the places where the two messages are defined:

https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/da0f04b5432a3adec175f9352a059058a1557533/src/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php#L99 https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/da0f04b5432a3adec175f9352a059058a1557533/src/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php#L106

rodrigoprimo avatar Nov 27 '24 18:11 rodrigoprimo

Valid suggestion. Low priority.

jrfnl avatar Nov 27 '24 20:11 jrfnl

Note: this would become more complex if #742 gets implemented.

jrfnl avatar Nov 27 '24 21:11 jrfnl