phpcs教程

安装方式(适用于mac)

安装composer
执行composer global require "squizlabs/php_codesniffer=*"
执行composer global config bin-dir --absolute打印composer 路径
设置软连接
ln -s composer路径/phpcs /usr/local/bin/phpcs
ln -s composer路径/phpcbf /usr/local/bin/phpcbf
如步骤3之后composer路径为/Users/yangxiao/.composer/vendor/bin
则执行:
ln -s /Users/yangxiao/.composer/vendor/bin/phpcs /usr/local/bin/phpcs
ln -s /Users/yangxiao/.composer/vendor/bin/phpcbf /usr/local/bin/phpcbf
如无权限 在ln 前+sudo 例如: sudo ln -s /Users/yangxiao/.composer/vendor/bin/phpcs /usr/local/bin/phpcs

IDE集成

Sublime Text(适用mac)

安装Package Control
command + shift + p 调出 安装界面 install package
输入phpcs 等待安装成功
Preferences->Package Settings->PHP Code Sniffer->Settings - User(Default)
配置phpcs 路径 "phpcs_executable_path": "/usr/local/bin/phpcs"
配置phpcbf 路径 "phpcbf_executable_path": "/usr/local/bin/phpcbf"

phpstrom

File -> Default Setting -> Languages & Frameworks -> PHP -> Code Sniffer -> ... -> 添加phpcs路径 -> Apply

File -> Default Setting -> Editor -> Inspections -> PHP -> PHP Code Sniffer validation (打上勾)-> Coding standard -> PSR2 -> Apply

File -> Default Setting -> Editor -> Inspections -> PHP -> PHP Mess Detector validation (打上勾)-> Options(选择相应规则) -> Apply

你可能感兴趣的:(phpcs教程)