php cs修复程序,如何运行风险规则?

php cs修复程序,如何运行风险规则?,php,configuration,command-line-interface,php-cs-fixer,Php,Configuration,Command Line Interface,Php Cs Fixer,嗨,我第一次使用php cs修复程序。我知道我们必须设置一个.php_cs.dist文件 这是我从php cs fixer的git存储库中获得的一个示例文件 $finder = PhpCsFixer\Finder::create() ->exclude('somedir') ->in(__DIR__); return PhpCsFixer\Config::create() ->setRules(array( '@Symfony' =&g

嗨,我第一次使用php cs修复程序。我知道我们必须设置一个.php_cs.dist文件

这是我从php cs fixer的git存储库中获得的一个示例文件

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

return PhpCsFixer\Config::create()
    ->setRules(array(
        '@Symfony' => true,
        'full_opening_tag' => false,
    ))
    ->setFinder($finder);
CLI上运行此命令时

php-cs-fixer-fix--config=.php\u-cs.dist--allow-risk

这是说,我需要给出允许有风险的选项,但在文档中没有提到如何设置允许有风险的选项来帮助我,越快越好

我的问题
如何运行风险规则?因为没有提到如何在php cs fixer中使用允许风险规则。

方法是
->setRiskyAllowed(true)

您的代码应该如下所示:

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

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

我同意此方法有些隐藏,在浏览源代码之前我没有找到它。

我们可以在命令行中启用允许风险选项,如下所示:

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

谢谢你的回答,但是你能告诉我php cs修复程序的工作效率吗?因为它不能像缩进一样正确地修复我的php文件。@Dherya我恐怕不能告诉你这一点。我以前用过它,它的工作原理应该是这样的。这是您可能想问GitHub软件包的作者的问题,超出了这个问题的范围。如果提供的信息解决了您最初的问题,请接受答案,以便其他人将来可以看到。