phpcs/phpmd/phpcpd/phpdcd/phplocをインストールしてみる
VirtualBoxにCentOSをとりあえずインストール
の続き
phpcs/phpmd/phpcpd/phpdcd/phplocをインストールしてみる。
インストール
まずrootになる。
$ su -
PHPとその他必要なパッケージをインストールする。
# yum -y install php php-pear php-devel php-dom
タイムゾーンを設定しておく。
あと、phpmdなど結構メモリが必要になるので、とりあえず512MBくらいに増やしておく。
# vi /etc/php.ini ・・・ date.timezone = "Asia/Tokyo" ・・・ memory_limit = 512M ・・・
チャネルを追加する。
※必要そうなのをとにかく追加しています。精査できてないです。
# pear channel-discover pear.phing.info # pear channel-discover pear.pdepend.org # pear channel-discover pear.phpunit.de # pear channel-discover pear.phpdoc.org # pear channel-discover pear.phpmd.org # pear channel-discover pear.symfony.com # pear channel-discover pear.symfony-project.com # pear channel-discover pear.netpirates.net # pear channel-discover components.ez.no # pear update-channels
ImageMagickをインストールする。
# yum -y install ImageMagick ImageMagick-devel gcc
# pecl install imagick ・・・ Please provide the prefix of Imagemagick installation [autodetect] : (Enter) ・・・
# vi /etc/php.d/imagick.ini extension=imagick.so
インストールする。
# pear install pdepend/PHP_Depend # pear install PHP_CodeSniffer # pear install phpmd/PHP_PMD # pear install phpunit/phpcpd # pear install phpunit/phpdcd-0.9.3 # pear install phpunit/phploc
インストールの確認
インストールされているのが確認できる。
# phpcs --version PHP_CodeSniffer version 1.5.3 (stable) by Squiz (http://www.squiz.net) # phpmd --version PHPMD 1.5.0 by Manuel Pichler # phpcpd --version phpcpd 2.0.0 by Sebastian Bergmann. # phpdcd --version phpdcd 0.9.3 by Sebastian Bergmann. # phploc --version phploc 2.0.4 by Sebastian Bergmann.
インストール完了。
# exit
サンプルプログラム
動作を試すためのサンプルプログラムとして、
シンプルなCMSのpicoをダウンロードする。
$ cd /tmp $ sudo yum -y install wget unzip $ wget https://github.com/picocms/Pico/archive/master.zip $ unzip master.zip $ mv Pico-master sample
phpcsを試してみる。
$ phpcs sample
・・・ 87 | ERROR | Spaces must be used to indent lines; tabs are not allowed 87 | ERROR | Line indented incorrectly; expected at least 4 spaces, found 1 87 | ERROR | Missing function doc comment 87 | ERROR | Public method name "Pico_Plugin::after_render" is not in camel | | caps format 87 | ERROR | Line indented incorrectly; expected 4 spaces, found 1 88 | ERROR | Spaces must be used to indent lines; tabs are not allowed 89 | ERROR | Spaces must be used to indent lines; tabs are not allowed 90 | ERROR | Spaces must be used to indent lines; tabs are not allowed 91 | ERROR | Spaces must be used to indent lines; tabs are not allowed -------------------------------------------------------------------------------- Time: 7.13 seconds, Memory: 35.25Mb
phpmdを試してみる
$ phpmd sample text cleancode,codesize,controversial,design,naming,unusedcode
/home/hoge/sample/lib/pico.php:12 The class Pico has an overall complexity of 58 which is very high. The configured complexity threshold is 50. /home/hoge/sample/lib/pico.php:20 The method __construct() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. /home/hoge/sample/lib/pico.php:20 The method __construct() has an NPath complexity of 40000. The configured NPath complexity threshold is 200. /home/hoge/sample/lib/pico.php:20 __construct accesses the super-global variable $_SERVER. ・・・ /home/hoge/sample/vendor/twig/twig/lib/Twig/TokenStream.php:79 Avoid using static access to class 'Twig_Token' in method 'expect'. /home/hoge/sample/vendor/twig/twig/lib/Twig/TokenStream.php:99 Avoid using static access to class 'Twig_Error_Syntax' in method 'look'. /home/hoge/sample/vendor/twig/twig/lib/Twig/TokenStream.php:122 Avoid using static access to class 'Twig_Token' in method 'isEOF'.
phpcpdを試してみる
$ phpcpd sample
phpcpd 2.0.0 by Sebastian Bergmann. Found 2 exact clones with 63 duplicated lines in 1 files: - /home/hoge/sample/vendor/michelf/php-markdown/Michelf/Markdown.php:561-603 /home/hoge/sample/vendor/michelf/php-markdown/Michelf/Markdown.php:2245-2287 - /home/hoge/sample/vendor/michelf/php-markdown/Michelf/Markdown.php:686-707 /home/hoge/sample/vendor/michelf/php-markdown/Michelf/Markdown.php:2376-2397 0.35% duplicated lines out of 17844 total lines of code. Time: 0 ms, Memory: 19.00Mb
phpdcdを試してみる
$ phpdcd sample
phpdcd 0.9.3 by Sebastian Bergmann. - Composer\Autoload\ClassLoader::add() declared in vendor/composer/ClassLoader.php:84 - Composer\Autoload\ClassLoader::addClassMap() declared in vendor/composer/ClassLoader.php:68 ・・・ - Pico_Plugin::plugins_loaded() declared in plugins/pico_plugin.php:12 - Pico_Plugin::request_url() declared in plugins/pico_plugin.php:22 Time: 0 ms, Memory: 23.25Mb
phplocを試してみる
$ phploc sample
phploc 2.0.4 by Sebastian Bergmann. Directories 22 Files 174 Size Lines of Code (LOC) 17844 Comment Lines of Code (CLOC) 4388 (24.59%) Non-Comment Lines of Code (NCLOC) 13456 (75.41%) Logical Lines of Code (LLOC) 3465 (19.42%) Classes 3249 (93.77%) Average Class Length 21 Average Method Length 3 Functions 192 (5.54%) Average Function Length 4 Not in classes or functions 24 (0.69%) Complexity Cyclomatic Complexity / LLOC 0.37 Cyclomatic Complexity / Number of Methods 2.40 Dependencies Global Accesses 45 Global Constants 28 (62.22%) Global Variables 4 (8.89%) Super-Global Variables 13 (28.89%) Attribute Accesses 1241 Non-Static 1231 (99.19%) Static 10 (0.81%) Method Calls 2190 Non-Static 2125 (97.03%) Static 65 (2.97%) Structure Namespaces 2 Interfaces 19 Traits 0 Classes 150 Abstract Classes 12 (8.00%) Concrete Classes 138 (92.00%) Methods 824 Scope Non-Static Methods 815 (98.91%) Static Methods 9 (1.09%) Visibility Public Method 639 (77.55%) Non-Public Methods 185 (22.45%) Functions 47 Named Functions 46 (97.87%) Anonymous Functions 1 (2.13%) Constants 44 Global Constants 8 (18.18%) Class Constants 36 (81.82%)