以下に、installや実行方法を記載しています。
https://github.com/phpmetrics/PhpMetrics
php の code metrics は、sonar qube でも可能ですが、 sonar qube の実行には、mysql等の準備もある為、PhpMetrics の方がお手軽な印象。
Step1 install Composer
phpのパッケージ管理システムである Composer を install します。
に記載のように以下の通り、実行すれば、OK
$ curl https://getcomposer.org/installer | /usr/local/bin/php $ sudo mv composer.phar /usr/local/bin/composer
Step2 install PhpMetrics
以下により、PhpMetrics が local へ installされます
$ composer require phpmetrics/phpmetrics --dev $ ls -lF 71 May 3 02:41 composer.json 4519 May 3 02:41 composer.lock 84 May 3 02:41 vendor/
Step3 run PhpMetrics
以下のように実行することで、 ~/path/to/php_sources 以下にある php source の code metrics が、 myreport 以下に html 形式で生成されます。
$ /usr/local/bin/php \ ./vendor/bin/phpmetrics \ --report-html=myreport \ ~/path/to/php_sources LOC Lines of code 27958 Logical lines of code 22461 Comment lines of code 5511 Average volume 1920.57 Average comment weight 22.07 Average intelligent content 22.07 Logical lines of code by class 147 Logical lines of code by method 17 Object oriented programming Classes 153 Interface 0 Methods 1300 Methods by class 8.5 Lack of cohesion of methods 2.61 Coupling Average afferent coupling 1.41 Average efferent coupling 1.56 Average instability 0.75 Depth of Inheritance Tree 1.51 Package Packages 3 Average classes per package 55 Average distance 0.24 Average incoming class dependencies 0.67 Average outgoing class dependencies 1.67 Average incoming package dependencies 0.67 Average outgoing package dependencies 0.67 Complexity Average Cyclomatic complexity by class 30.23 Average Weighted method count by class 37.98 Average Relative system complexity 100.2 Average Difficulty 15.35 Bugs Average bugs by class 0.64 Average defects by class (Kan) 1.89 Violations Critical 0 Error 97 Warning 62 Information 30 Done