Skip to content

Commit

Permalink
Generic/DisallowYodaConditions: ?? should not trigger the sniff
Browse files Browse the repository at this point in the history
This commit changes the DisallowYodaConditions sniff so that the null
coalescing operator (`??`) does not trigger it.
  • Loading branch information
rodrigoprimo committed Apr 22, 2024
1 parent 8d2363d commit e4d3743
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class DisallowYodaConditionsSniff implements Sniff
*/
public function register()
{
return Tokens::$comparisonTokens;
$tokens = Tokens::$comparisonTokens;
unset($tokens[T_COALESCE]);

return $tokens;

}//end register()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,5 @@ echo match ($text) {
'foo' => 10 === $y,
10 === $y => 'bar',
};

1 ?? $nullCoalescingShouldNotTriggerSniff;

0 comments on commit e4d3743

Please sign in to comment.