4

I installed php-cs-fixer globally by running

$ wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -O php-cs-fixer

followed by running

$ sudo chmod a+x php-cs-fixer
$ sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer

When I try to run php-cs-fixer with

$ php-cs-fixer -vv fix /home/xxx/host/master/src/AppBundle/Command/GenerateERPContractInvoicesCommand.php --config=sf2

this results in the following error message:

[PhpCsFixer\ConfigurationException\InvalidConfigurationException (16)]
Cannot read config file "sf2"

An attempt to run with --config=sf23 results in the same error message.

Trying to run like this

$ php-cs-fixer fix src/AppBundle/Command/GenerateERPContractInvoicesCommand.php --level=symfony 

results in the error message

The "--level" option does not exist.

Then I create a configuration file.php_cs with the content

<?php

$finder = Symfony\CS\Finder::create()
    ->exclude([
        'app', 
        'spec', 
        'build', 
        'bin', 
        'web', 
        'vendor',
    ])
    ->in(__DIR__);

return Symfony\CS\Config::create()
    ->fixers([
        'short_array_syntax', 
        '-phpdoc_align',
        'ordered_use',
    ])
    ->finder($finder);

and receive the following error message:

[PhpCsFixer\ConfigurationException\InvalidConfigurationException]
The config file: "/home/ivan/host/master/.php_cs" does not return a "PhpCsFixer\ConfigInterface" instance. Got: "integer".

How do I use php-cs-fixer for Symfony, can you help?

Where can I get the configuration for Symfony, and how do I correctly use php-cs-fixer for a Symfony project ?

localheinz
  • 9,179
  • 2
  • 33
  • 44
shuba.ivan
  • 3,824
  • 8
  • 49
  • 121

3 Answers3

4

According to the documentation, you may want to run with rules argument :

php php-cs-fixer.phar fix /path/to/project --rules=@Symfony
Julien Deniau
  • 4,880
  • 1
  • 18
  • 22
4

I use the following command in our ci dev builds:

php-cs-fixer fix --using-cache=no --rules=@Symfony src
Souhaieb
  • 559
  • 8
  • 12
Sam Janssens
  • 1,491
  • 1
  • 12
  • 30
2

The issue is that you are doing all your work (cli params, config file) like for PHP CS Fixer v1, yet you are downloading v2. If you want to know how to migrate, check out upgrade guide: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/UPGRADE.md

keradus
  • 534
  • 2
  • 5