Skip to content

Commit 3284f1f

Browse files
committed
SlevomatCodingStandard.ControlStructures.DisallowYodaComparison: Fixed fixer
1 parent a343cd7 commit 3284f1f

9 files changed

+28
-4
lines changed

SlevomatCodingStandard/Helpers/YodaHelper.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use const T_BOOLEAN_AND;
2424
use const T_BOOLEAN_OR;
2525
use const T_CASE;
26-
use const T_CLOSE_CURLY_BRACKET;
2726
use const T_CLOSE_PARENTHESIS;
2827
use const T_CLOSE_SHORT_ARRAY;
2928
use const T_COALESCE;
@@ -343,7 +342,6 @@ private static function getStopTokenCodes(): array
343342
T_COLON => true,
344343
T_RETURN => true,
345344
T_COMMA => true,
346-
T_CLOSE_CURLY_BRACKET => true,
347345
T_MATCH_ARROW => true,
348346
T_FN_ARROW => true,
349347
];

tests/Sniffs/ControlStructures/DisallowYodaComparisonSniffTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public function testErrors(): void
2222
self::assertSniffError($report, $lineNumber, DisallowYodaComparisonSniff::CODE_DISALLOWED_YODA_COMPARISON);
2323
}
2424

25-
self::assertSniffError($report, 41, DisallowYodaComparisonSniff::CODE_DISALLOWED_YODA_COMPARISON);
25+
self::assertSniffError($report, 39, DisallowYodaComparisonSniff::CODE_DISALLOWED_YODA_COMPARISON);
26+
self::assertSniffError($report, 45, DisallowYodaComparisonSniff::CODE_DISALLOWED_YODA_COMPARISON);
2627
}
2728

2829
public function testFixable(): void

tests/Sniffs/ControlStructures/RequireYodaComparisonSniffTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public function testErrors(): void
2121
self::assertSniffError($report, $lineNumber, RequireYodaComparisonSniff::CODE_REQUIRED_YODA_COMPARISON);
2222
}
2323

24-
self::assertSniffError($report, 41, RequireYodaComparisonSniff::CODE_REQUIRED_YODA_COMPARISON);
24+
self::assertSniffError($report, 39, RequireYodaComparisonSniff::CODE_REQUIRED_YODA_COMPARISON);
25+
self::assertSniffError($report, 45, RequireYodaComparisonSniff::CODE_REQUIRED_YODA_COMPARISON);
2526
}
2627

2728
public function testFixable(): void

tests/Sniffs/ControlStructures/data/disallowYodaComparisonErrors.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
A::TYPE_A === $param xor $param === A::TYPE_B;
3737
$x = [$a, $b, $c] === $username;
3838

39+
if (null === $row->{self::NAME}) {
40+
return 0;
41+
}
42+
3943
function ($condition, $actual) {
4044
return match ($condition) {
4145
'anything' => 1 === $actual,

tests/Sniffs/ControlStructures/data/fixableDisallowYodaComparisons.fixed.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
// ...
7171
}
7272

73+
if ($row->{self::NAME} === null) {
74+
return 0;
75+
}
76+
7377
function ($condition, $actual) {
7478
return match ($condition) {
7579
'anything' => $actual === 1,

tests/Sniffs/ControlStructures/data/fixableDisallowYodaComparisons.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
// ...
7171
}
7272

73+
if (null === $row->{self::NAME}) {
74+
return 0;
75+
}
76+
7377
function ($condition, $actual) {
7478
return match ($condition) {
7579
'anything' => 1 === $actual,

tests/Sniffs/ControlStructures/data/fixableRequireYodaComparisons.fixed.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
A::TYPE_A === $param or A::TYPE_B === $param;
6868
A::TYPE_A === $param xor A::TYPE_B === $param;
6969

70+
if (null === $row->{self::NAME}) {
71+
return 0;
72+
}
73+
7074
function ($condition, $actual) {
7175
return match ($condition) {
7276
'anything' => 1 === $actual,

tests/Sniffs/ControlStructures/data/fixableRequireYodaComparisons.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
A::TYPE_A === $param or $param === A::TYPE_B;
6868
$param === A::TYPE_A xor A::TYPE_B === $param;
6969

70+
if ($row->{self::NAME} === null) {
71+
return 0;
72+
}
73+
7074
function ($condition, $actual) {
7175
return match ($condition) {
7276
'anything' => $actual === 1,

tests/Sniffs/ControlStructures/data/requireYodaComparisonErrors.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
$param === A::TYPE_A xor A::TYPE_B === $param;
3737
$x = $username === [$a, $b, $c];
3838

39+
if ($row->{self::NAME} === null) {
40+
return 0;
41+
}
42+
3943
function ($condition, $actual) {
4044
return match ($condition) {
4145
'anything' => $actual === 1,

0 commit comments

Comments
 (0)