Skip to content

Commit

Permalink
bug #4934 YodaStyleFixer - fix for conditions weird are (kubawerlos)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.15 branch (closes #4934).

Discussion
----------

YodaStyleFixer - fix for conditions weird are

While on the [other](#4929) fix working I was, it thinking me made what the reason is for these conditions:
```php
            if ($token->isComment() || $token->isWhitespace()) {
                if ($expectNothing) {
                    return false;
                }

                continue;
            }
```
Why do the check we want for `$expectNothing` only for comments and whitespaces, expect the opposite I would. So these 2 test case added I have and what weird is only 1 failed has: https://travis-ci.org/github/FriendsOfPHP/PHP-CS-Fixer/jobs/678270023

The fix to not nest them is, @bgotink, @keradus and @SpacePossum I ping (as they the authors are) to review.

May the force be with you.

Commits
-------

60dc742 YodaStyleFixer - fix for conditions weird are
  • Loading branch information
SpacePossum committed May 14, 2020
2 parents cb3bdd6 + 60dc742 commit 5fbbc1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Fixer/ControlStructure/YodaStyleFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,13 +665,13 @@ private function isConstant(Tokens $tokens, $index, $end)
$token = $tokens[$index];

if ($token->isComment() || $token->isWhitespace()) {
if ($expectNothing) {
return false;
}

continue;
}

if ($expectNothing) {
return false;
}

if ($expectNumberOnly && !$token->isGivenKind([T_LNUMBER, T_DNUMBER])) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixer/ControlStructure/YodaStyleFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ public function provideFixCases()
['<?php $a = $b[$key]["1"] === $c["2"];'],
['<?php return $foo->$a[1] === $bar[$baz]{1}->$a[1][2][3]->$d[$z]{1};'],
['<?php return $foo->$a === $foo->$b->$c;'],
['<?php return $x === 2 - 1;'],
['<?php return $x === 2-1;'],
// https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/693
['<?php return array(2) == $o;'],
['<?php return $p == array(2);'],
Expand Down

0 comments on commit 5fbbc1a

Please sign in to comment.