让我们尝试使用PHP CodeSniffer来检查是否遵守了编码规范

获取 PHP_CodeSniffer。

git clone https://github.com/squizlabs/PHP_CodeSniffer.git phpcs

添加WordPress的编码规范

git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs

cd phpcs

./scripts/phpcs --config-set installed_paths ../wpcs

请确认可以查看的编码规约清单

$ phpcs -i
The installed coding standards are Squiz, Zend, PSR1, PSR2, PHPCS, MySource, PEAR, WordPress-Extra, WordPress-Docs, WordPress, WordPress-VIP and WordPress-Core

检查编码规范

    ディテクトリ単位
phpcs --standard=WordPress --report=summary  htdocs/wp-content/themes/origin_theme
    ファイル単位
phpcs --standard=WordPress htdocs/wp-content/themes/origin_theme/index.php

更改默认的编码规范

phpcs --config-set default_standard WordPress

参考资料:
– PHP_CodeSniffer的wiki页面:https://github.com/squizlabs/PHP_CodeSniffer/wiki
– WordPress-Coding-Standards的GitHub页面:https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards

bannerAds