vscode 中使用php-cs-fixer和PHP Formatter 插件规范化PHP代码

   它是php-fig组织定义的PHP代码规范,良好的代码规范可以提高代码可读性,团队沟通维护成本
   使用它可以按照指定的规范格式化您的PHP代码,此工具不仅可以检测有不符合规范的代码,而且还可以修复它们
 
vscode 中使用php-cs-fixer和PHP Formatter 插件规范化PHP代码
 
1.使用php-cs-fixer.phar格式化php文件
        1.下载php-cs-fixer.phar到任意目录,尽量放到php目录下)
        2.在VScode里手动调用php-cs-fixer.phar进行格式化
vscode 中使用php-cs-fixer和PHP Formatter 插件规范化PHP代码
 
 
2.在Vscode里PHP Formatter 插件
    1.下载php-cs-fixer.phar到任意目录,尽量放到php目录下)
    2.安装PHP Formatter 插件并进行自定义设置(php路径、php-cs-fixer.phar路径,Rules等)
    3.自定义PHP Formatter 插件的快捷键
 
vscode 中使用php-cs-fixer和PHP Formatter 插件规范化PHP代码
 
配置信息如下:
 
//打印日志信息,用于调试
"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自定义快捷键配置
vscode 中使用php-cs-fixer和PHP Formatter 插件规范化PHP代码
 
vscode 中使用php-cs-fixer和PHP Formatter 插件规范化PHP代码
 
参考: