什麼是PHP-CS-Fixer?
它是php-fig組織定義的PHP代碼規範,良好的代碼規範可以提高代碼可讀性,團隊溝通維護成本
使用它可以按照指定的規範格式化您的PHP代碼,此工具不僅可以檢測有不符合規範的代碼,而且還可以修複它們

1.使用php-cs-fixer.phar格式化php檔案
1.下載下傳php-cs-fixer.phar到任意目錄,盡量放到php目錄下)
2.在VScode裡手動調用php-cs-fixer.phar進行格式化
2.在Vscode裡PHP Formatter 插件
1.下載下傳php-cs-fixer.phar到任意目錄,盡量放到php目錄下)
2.安裝PHP Formatter 插件并進行自定義設定(php路徑、php-cs-fixer.phar路徑,Rules等)
3.自定義PHP Formatter 插件的快捷鍵
//列印日志資訊,用于調試
"phpformatter.logging":true,
//不使用composer方式
"phpformatter.composer":false,
//添加自定義參數,預設的參數level已經在新版本中移出是以會導緻運作出錯
//RULES=[@PSR1,@PSR2,@Symfony]
//source:https://github.com/FriendsOfPHP/PHP-CS-Fixer#usage
"phpformatter.arguments":["--rules=@Symfony"],
// Should point to php-cs-fixer.phar file, if you have installed this manually (without Composer). Should include .phar extension.
// php-cs-fixer.phar路徑,使用composer方式時可以不填
"phpformatter.pharPath":"d:/wamp/bin/php/php5.5.12/php-cs-fixer.phar",
// If the pharPath is set, and you are not using Composer, and you haven't added PHP to your PATH, this should point to the php.exe file.
// php路徑,使用composer方式時可以不填
"phpformatter.phpPath":"d:/wamp/bin/php/php5.5.12/php.exe"
VScode自定義快捷鍵配置
參考:
PHP-CS-Fixer:格式化你的PHP代碼
vscode-php-formatter issues
使用 PHP-CS-Fixer 自動規範化你的 PHP 代碼
VSCode安裝php格式化工具php formatter
github PHP-CS-Fixer
vscode plugin PHP Formatter
PHP PSR-2 代碼風格規範(中文版) -SegmentFault
PSR-2: Coding Style Guide
php-cs-fixer (PHP Coding Standards Fixer)
From WizNote