Php/codesniffer
提供: 初心者エンジニアの簡易メモ
目次
codesnifferとは
コーディング規約のチェックツール
pearでインストール
pear install PHP_CodeSniffer-1.3.2
composerでインストール
composer global require squizlabs/php_codesniffer
php_codesnifferのパスを通す
$ echo 'export PATH=$HOME/.composer/vendor/bin:$PATH' >> ~/.zshrc $ source ~/.zshrc
バージョン確認
$ phpcs --version PHP_CodeSniffer version 3.11.2 (stable) by Squiz and PHPCSStandards
チェック方法
phpcs -v sample.php
psr12のチェック方法
phpcs --standard=PSR12 sample.php
1 | ERROR | [x] Header blocks must be separated by a single blank line 2 | ERROR | [x] PHP keywords must be lowercase; expected "or" but found "OR" 4 | ERROR | [ ] Each class must be in a namespace of at least one level (a top-level vendor name) 10 | WARNING | [ ] Visibility must be declared on all constants if your project supports PHP 7.1 or later
自動整形
phpcbf --standard=PSR12 sample.php