我整天都在为此苦苦挣扎。我被引入了一个新应用程序,他们需要在所有文件上运行 php-cs-fixer。该项目中有一个 .php_cs 文件,但我无法让它在 sublime text 3 中工作,也无法让 vscode 去做。
命令运行,但我收到错误:
PHP Fatal error: Uncaught Error: Class 'Symfony\CS\Config\Config' not found in C:\dev\code\.php_cs:63
Stack trace:
#0 C:\Users\Alex\AppData\Roaming\Composer\vendor\friendsofphp\php-cs-fixer\src\Console\ConfigurationResolver.php(933): include()
#1 C:\Users\Alex\AppData\Roaming\Composer\vendor\friendsofphp\php-cs-fixer\src\Console\ConfigurationResolver.php(228): PhpCsFixer\Console\ConfigurationResolver::separatedContextLessInclude('c:\\dev\\code\\Tao...')
#2 C:\Users\Alex\AppData\Roaming\Composer\vendor\friendsofphp\php-cs-fixer\src\Console\ConfigurationResolver.php(625): PhpCsFixer\Console\ConfigurationResolver->getConfig()
#3 C:\Users\Alex\AppData\Roaming\Composer\vendor\friendsofphp\php-cs-fixer\src\Console\ConfigurationResolver.php(458): PhpCsFixer\Console\ConfigurationResolver->getFormat()
#4 C:\Users\Alex\AppData\Roaming\Composer\vendor\friendsofphp\php-cs-fixer\src\Console\Command\FixCommand.php(151): PhpCsFixer\Console\ConfigurationResolver->getReporter()
#5 C:\Users\Alex\AppData\Roaming\Composer\vendor\symfony in C:\dev\code\.php_cs on line 63
这是 .php_cs 文件
<?php
$finder = Symfony\Component\Finder\Finder::create()
->files()
->in(__DIR__)
->exclude('vendor')
->exclude('resources/views')
->exclude('storage')
->exclude('public')
->notName("*.txt")
->ignoreDotFiles(true)
->ignoreVCS(true);
$fixers = [
'-psr0',
'-php_closing_tag',
'blankline_after_open_tag',
'double_arrow_multiline_whitespaces',
'duplicate_semicolon',
'empty_return',
'extra_empty_lines',
'include',
'join_function',
'list_commas',
'multiline_array_trailing_comma',
'namespace_no_leading_whitespace',
'no_blank_lines_after_class_opening',
'no_empty_lines_after_phpdocs',
'object_operator',
'operators_spaces',
'phpdoc_indent',
'phpdoc_no_access',
'phpdoc_no_package',
'phpdoc_scalar',
'phpdoc_short_description',
'phpdoc_to_comment',
'phpdoc_trim',
'phpdoc_type_to_var',
'phpdoc_var_without_name',
'remove_leading_slash_use',
'remove_lines_between_uses',
'return',
'self_accessor',
'single_array_no_trailing_comma',
'single_blank_line_before_namespace',
'single_quote',
'spaces_before_semicolon',
'spaces_cast',
'standardize_not_equal',
'ternary_spaces',
'trim_array_spaces',
'no_useless_else',
'unalign_equals',
'unary_operators_spaces',
'whitespacy_lines',
'multiline_spaces_before_semicolon',
'short_array_syntax',
'short_echo_tag',
'concat_with_spaces',
'ordered_use',
];
return Symfony\CS\Config\Config::create()
->fixers($fixers)
->finder($finder)
->setUsingCache(true);
我可以通过转到 cmd 提示符并运行来手动运行该文件
php-cs-fixer fix .\Controller.php
它做了它应该做的事情,我认为使用默认的 .php_cs 文件。驱赶我蝙蝠。:)