Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php cs fixer, how to run risky rules?

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.

like image 616
Dherya Avatar asked Feb 16 '17 14:02

Dherya


People also ask

How do I run PHP fixer?

To use PHP CS Fixer from PhpStorm instead of command line, you need to register it in PhpStorm and configure it as a PhpStorm code inspection. Once installed and enabled in PhpStorm, the tool is available in any opened PHP file, and no additional steps are required to launch it.

What is Friendsofphp?

A tool to automatically fix PHP Coding Standards issues.


2 Answers

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.

like image 64
OptimusCrime Avatar answered Oct 13 '22 23:10

OptimusCrime


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
like image 20
Colin Lai Avatar answered Oct 13 '22 23:10

Colin Lai