Skip to content

Commit e4d3743

Browse files
committed
Generic/DisallowYodaConditions: ?? should not trigger the sniff
This commit changes the DisallowYodaConditions sniff so that the null coalescing operator (`??`) does not trigger it.
1 parent 8d2363d commit e4d3743

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Standards/Generic/Sniffs/ControlStructures/DisallowYodaConditionsSniff.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class DisallowYodaConditionsSniff implements Sniff
2525
*/
2626
public function register()
2727
{
28-
return Tokens::$comparisonTokens;
28+
$tokens = Tokens::$comparisonTokens;
29+
unset($tokens[T_COALESCE]);
30+
31+
return $tokens;
2932

3033
}//end register()
3134

src/Standards/Generic/Tests/ControlStructures/DisallowYodaConditionsUnitTest.inc

+2
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,5 @@ echo match ($text) {
173173
'foo' => 10 === $y,
174174
10 === $y => 'bar',
175175
};
176+
177+
1 ?? $nullCoalescingShouldNotTriggerSniff;

0 commit comments

Comments
 (0)