Skip to content

Commit

Permalink
Fixed YodaComparisonSniff for logical "and", "or" and "xor"
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Aug 23, 2017
1 parent 4c41888 commit cb6986f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ private function getStopTokenCodes(): array
T_OPEN_TAG => true,
T_INLINE_THEN => true,
T_INLINE_ELSE => true,
T_LOGICAL_AND => true,
T_LOGICAL_OR => true,
T_LOGICAL_XOR => true,
T_COALESCE => true,
T_CASE => true,
T_COLON => true,
Expand Down
2 changes: 1 addition & 1 deletion tests/Sniffs/ControlStructures/YodaComparisonSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testCorrectFile()
public function testIncorrectFile()
{
$resultFile = $this->checkFile(__DIR__ . '/data/allYodaComparisons.php');
foreach (range(3, 33) as $lineNumber) {
foreach (range(3, 36) as $lineNumber) {
$this->assertSniffError($resultFile, $lineNumber, YodaComparisonSniff::CODE_YODA_COMPARISON);
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Sniffs/ControlStructures/data/allYodaComparisons.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
array(self::ADMIN_EMAIL === $username ? self::ROLE_ADMIN : self::ROLE_CUSTOMER);
[[] === $array];
[array() === $array];
A::TYPE_A === $param and A::TYPE_B === $param;
$param === A::TYPE_A or A::TYPE_B === $param;
A::TYPE_A === $param xor $param === A::TYPE_B;
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@
$x = array($username === [] ? true : false);
$x = [$username === array() ? true : false];
$x = [$username === [] ? true : false];

$param === A::TYPE_A and $param === A::TYPE_B;
$param === A::TYPE_A or $param === A::TYPE_B;
$param === A::TYPE_A xor $param === A::TYPE_B;
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@
$x = array([] === $username ? true : false);
$x = [array() === $username ? true : false];
$x = [[] === $username ? true : false];

A::TYPE_A === $param and A::TYPE_B === $param;
$param === A::TYPE_A or A::TYPE_B === $param;
A::TYPE_A === $param xor $param === A::TYPE_B;
4 changes: 4 additions & 0 deletions tests/Sniffs/ControlStructures/data/noYodaComparisons.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@
array($username === self::ADMIN_EMAIL ? self::ROLE_ADMIN : self::ROLE_CUSTOMER);
[$array === []];
[$array === array()];

$param === A::TYPE_A and $param === A::TYPE_B;
$param === A::TYPE_A or $param === A::TYPE_B;
$param === A::TYPE_A xor $param === A::TYPE_B;

0 comments on commit cb6986f

Please sign in to comment.