phpvisual-studio-codesublimetext3linterphp-cs-fixer

Uncaught Error: Class 'Symfony\CS\Config\Config' not found


I've been struggling with this all day. I got brought in to a new app and they require php-cs-fixer to be ran on all files. The project has a .php_cs file in it, but I couldn't get it work in sublime text 3 nor could I get vscode to do it.

The command runs but I get the error:

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

Here is the .php_cs file

<?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);

I can run the file manually by going to the cmd prompt and running

php-cs-fixer fix .\Controller.php

And it does what it's supposed to, I think with a default .php_cs file. Driving me bats. :)


Solution

  • Problem is we were trying to use an older version of php-cs-fixer and it didn't function correctly with our version of php.

    Fix was to update to php-cs-fixer v2.*