Php-cs-fixer: How to disable this changes as below?

Created on 29 May 2018  ·  3Comments  ·  Source: FriendsOfPHP/PHP-CS-Fixer

how to disable this?
image

The PHP version you are using ($ php -v):

PHP 7.1.14-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Feb  9 2018 09:33:27) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.14-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

PHP CS Fixer version you are using ($ php-cs-fixer -V):

PHP CS Fixer 2.10.4 Bowling Bear by Fabien Potencier and Dariusz Ruminski (b2dce1d)

The configuration file you are using, if any:

return PhpCsFixer\Config::create()

    ->setRiskyAllowed(true)

    ->setRules([
        '@Symfony' => true,

        '@Symfony:risky' => true,

        'array_syntax' => ['syntax' => 'short'],

        'combine_consecutive_unsets' => true,

        // one should use PHPUnit methods to set up expected exception instead of annotations

        'general_phpdoc_annotation_remove' => ['expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp'],

        //'header_comment' => array('header' => $header),

        'heredoc_to_nowdoc' => true,

        'no_extra_consecutive_blank_lines' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],

        'no_unreachable_default_argument_value' => true,

        'no_useless_else' => true,

        'no_useless_return' => true,

        'ordered_class_elements' => true,

        'ordered_imports' => true,

        'php_unit_strict' => true,

        'phpdoc_add_missing_param_annotation' => true,

        'no_trailing_comma_in_singleline_array' => true, //单行数组最后一个元素不添加逗号

        'phpdoc_order' => true,

        'psr4' => true,

        'strict_comparison' => false,

        'strict_param' => false, //这里设置为true,发现in_array方法会默认加上第3个参数为true,这使得in_array会对前两个参数值的类型也会做严格的校验,建议设置为false

        'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => true],

        'concat_space' => ['spacing' => 'one'],

        'no_empty_statement' => true,

        'simplified_null_return' => true,

        'no_extra_consecutive_blank_lines' => true,

        'pre_increment' => false, //设置为false,$i++ 不会变成 ++$i
    ])

    ->setFinder(
        PhpCsFixer\Finder::create()

            ->exclude('vendor')

            ->in(__DIR__)
    )

    ->setUsingCache(false)

;

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
if ($res && $type == 0) {
}

  • with unexpected changes applied when running PHP CS Fixer:
if ($res && 0 == $type) {
}
kinquestion

All 3 comments

please follow the issue template that was given during issue creation : https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/2.11/.github/ISSUE_TEMPLATE

you might hit that output by many different way. you are using yoda rule and that's what doing given changes. how you configured it? for that, we need to see answers for questions from issue template

in your config file you are using @Symfony ruleset, which is using yoda_style under the hood.
add yoda_style => false to your config to disable the rule (or configure it to your needs, eg to convert all yoda into non-yoda conditions - vide docs)

thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

datenmeister picture datenmeister  ·  3Comments

ro0NL picture ro0NL  ·  3Comments

grachevko picture grachevko  ·  3Comments

ndench picture ndench  ·  3Comments

Bilge picture Bilge  ·  3Comments