Mac安裝Package Control: command + ~ 快捷鍵調出控制檯,貼上下面程式碼
import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())
command+Shift+P 輸入install,如圖,回車
搜尋PHPcs並安裝,
Preferences -> Package Setting -> PHP Code Sniffer -> Setting – Default 並且儲存,錯誤提示檔案不存在,
mkdir ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Phpcs
然後安裝依賴包
composer global require squizlabs/php_codesniffer
composer global require phpmd/phpmd
composer global require friendsofphp/php-cs-fixer
安裝後會在
ls /Users/ace/.composer/vendor/bin
看到
pdepend php-cs-fixer phpcbf phpcs phpmd
在~/.zshrc新增
export PATH="/Users/ace/.composer/vendor/bin:$PATH"
回到sublime,Preferences -> Package Setting -> PHP Code Sniffer -> Setting – User中新增,要注意路徑和中的使用者名稱是自己的
{
"phpcs_php_path": "/usr/local/opt/php/bin/php",
"phpcs_executable_path": "/Users/ace/.composer/vendor/bin/phpcs",
"php_cs_fixer_executable_path": "/Users/ace/.composer/vendor/bin/php-cs-fixer",
"phpcbf_executable_path": "/Users/ace/.composer/vendor/bin/phpcbf",
"phpmd_executable_path": "/Users/ace/.composer/vendor/bin/phpmd",
"phpcs_additional_args": {
"--standard": "PSR2",
"-n": ""
},
"phpcs_show_errors_on_save": true,
"phpcs_outline_for_errors": false,
"php_cs_fixer_on_save": false
}