vscode 中使用php-cs-fixer和PHP Formatter 插件规范化PHP代码
Posted huangtailang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vscode 中使用php-cs-fixer和PHP Formatter 插件规范化PHP代码相关的知识,希望对你有一定的参考价值。
它是php-fig组织定义的PHP代码规范,良好的代码规范可以提高代码可读性,团队沟通维护成本
使用它可以按照指定的规范格式化您的PHP代码,此工具不仅可以检测有不符合规范的代码,而且还可以修复它们

1.使用php-cs-fixer.phar格式化php文件

2.在Vscode里PHP Formatter 插件
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自定义快捷键配置


参考:
以上是关于vscode 中使用php-cs-fixer和PHP Formatter 插件规范化PHP代码的主要内容,如果未能解决你的问题,请参考以下文章