Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pear CodeSniffer Cyclomatic Complexity

The Pear CodeSniffer seems to come with a Cyclomatic Complexity Sniff (CyclomaticComplexitySniff.php). Does anyone know how to use it? I'd like to calculate the complexity of the code I'm analyzing. I'd like to use the Zend coding standard, but no matter what standard I use though, I don't see complexity information being output.

If anyone has advice regarding this, please let me know.

Thanks.

like image 302
Dinesh Kumar Sarangapani Avatar asked Sep 06 '25 21:09

Dinesh Kumar Sarangapani


1 Answers

I have managed to make it work by using the following command:

phpcs <dir|file> -p -s 
  --sniffs=Generic.Metrics.CyclomaticComplexity --standard=Squiz

If you want to see the cyclomatic complexity for all functions instead of only the ones that exceed the default threshold, you have to set the value for complexity to 0 in the file "PEAR\PHP\CodeSniffer\Standards\Squiz\ruleset.xml":

 <rule ref="Generic.Metrics.CyclomaticComplexity">
   <properties>
     <property name="complexity" value="0"/>
like image 160
Paul Jansen Avatar answered Sep 08 '25 11:09

Paul Jansen