「Php/codesniffer」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→php_codesnifferのパスを通す) |
(→psr12のチェック方法) |
||
(同じ利用者による、間の1版が非表示) | |||
行18: | 行18: | ||
==チェック方法== | ==チェック方法== | ||
phpcs -v sample.php | phpcs -v sample.php | ||
+ | |||
+ | ==psr12のチェック方法== | ||
+ | phpcs --standard=PSR12 sample.php | ||
+ | <pre> | ||
+ | 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 | ||
+ | </pre> | ||
+ | |||
+ | ==自動整形== | ||
+ | phpcbf --standard=PSR12 sample.php |
2024年12月17日 (火) 00:00時点における最新版
目次
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