新建composer.json 文件
{ "require" :{ "fabpot/php-cs-fixer":"2.16.3" },"config": { "secure-http": false } }
这里注意你要使用的php-cs-fixer 的版本
在命令行执行 composer update 命令
设置全局:
找到安装目录 设置全局变量 D:\tools\php-cs-fixer\vendor\bin
在PHPstorm 中 新增工具插件
Name: php-cs-fixer Program: D:\tools\php-cs-fixer\vendor\bin\php-cs-fixer.bat Arguments: fix $FileDir$/$FileName$ --config=.php_cs.dist Working director: $ProjectFileDir$
一定要保证安装的php-cs-fixer版本和 .php_cs.dist 保持一致
Arguments的值设置为 fix $FileDir$/$FileName$ --config=.php_cs.dist 这样 是针对单文件进行格式化的,如果想要批量针对指定目录下的所有文件 需要修改为 fix $FileDir$ --config=.php_cs.dist
第一种
$ mkdir --parents tools/php-cs-fixer $ composer require --working-dir=tools/php-cs-fixer friendsofphp/php-cs-fixer
第二种 新增comopser.json 文件 然后执行 composer update
{ "require": { "friendsofphp/php-cs-fixer": "^3.8" } }
在phpstorm中 File | Settings | Tools | External Tools 增加扩展工具类
Name: php-cs-fixer3 Program: D:\tools\php-cs-fixer\vendor\bin\php-cs-fixer.bat Arguments: fix $FileDir$/$FileName$ --config=.php-cs-fixer.dist.php Working director: $ProjectFileDir$
联系客服