php cs fixer, how to run risky rules?
Asked Answered
L

2

12

PHP-CS-FIXER

Hi I am using php-cs-fixer for first time. I know that we have to set a .php_cs.dist file

This is a example file that i got from the git repository of php-cs-fixer.

$finder = PhpCsFixer\Finder::create()
    ->exclude('somedir')
    ->in(__DIR__);

return PhpCsFixer\Config::create()
    ->setRules(array(
        '@Symfony' => true,
        'full_opening_tag' => false,
    ))
    ->setFinder($finder);

When i am running this command on CLI

php-cs-fixer fix --config=.php_cs.dist --allow-risky

It is saying that i need to give options to --allow-risky but in documentation it is nothing mention that how to set option for allow risky help me out guys.The sooner the better.

my question How to run risky rules? As there is nothing mentioned that how to use allow risky rule in php-cs-fixer.

Leff answered 16/2, 2017 at 14:24 Comment(0)
A
24

The method is ->setRiskyAllowed(true). Implementation code.

Your code should look something like this:

$finder = PhpCsFixer\Finder::create()
    ->exclude('somedir')
    ->in(__DIR__);

return PhpCsFixer\Config::create()
    ->setRiskyAllowed(true)
    ->setRules(array(
        '@Symfony' => true,
        'full_opening_tag' => false,
    ))
    ->setFinder($finder);

I agree that this method is somewhat hidden, and I did not find it before I browsed the source code.

Anastomose answered 16/2, 2017 at 14:33 Comment(2)
Thanks for your answer but can you tell me how effectively php-cs-fixer works because it's not able to fix my php files correctly like indentation.Leff
@Dherya I am afraid I can not tell you that. I've used it before and it worked like it should. This is something you may want to ask the author of the package at GitHub and is outside the scope of this question. If the provided information solved your initial problem, please accept the answer so others can see it in the future.Anastomose
B
6

We can enable the allow risky option in the command line like the following:

php-cs-fixer fix --config=.php_cs.dist --allow-risky=yes
Betide answered 20/4, 2017 at 2:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.