码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-03-23 12:21:11      阅读:3134      评论:0      收藏:0      [点我收藏+]

标签:point   成本   ppa   团队   html   odi   版本   composer   segment   

   它是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自定义快捷键配置
技术分享
 
技术分享
 
参考:





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

标签:point   成本   ppa   团队   html   odi   版本   composer   segment   

原文地址:http://www.cnblogs.com/huangtailang/p/6604124.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!