-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Squiz.PHP.DisallowComparisonAssignment false positive for PHP 8 match expression #3616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm not having any luck reproducing this issue with the code sample and ruleset supplied. I also tried PHP 7.4 and PHPCS 3.6.2 to see if it was an older issue but can't reproduce there as well. The only thing I can't test on is Windows, but that shouldn't impact things. Looking at the code of the sniff, I'm not sure how the sample code would even think there is a comparison token in there. Are you sure this sample file produces the error? If so, can you run phpcs wit the |
@gsherwood Thanks for your answer. You are right. My example was wrong. Sorry for that. I edited the example in the start post. |
@FFirmenich I've been able to reproduce your issue with the updated code sample. A fix has been pulled in PR #3624. Testing appreciated. Just out of curiousity: why are you using the " The below effectively does exactly the same without the extra cognitive load: function test() {
$food = 'cake';
$returnValue = match ($food) {
'apple' => 'This food is an apple',
'bar' => 'This food is a bar',
'cake' => 'This food is a cake',
};
} |
@FFirmenich Thanks a lot for fixing the code sample, and big thanks to @jrfnl for actually fixing the bug. |
@jrfnl Thanks for fixing it!
Check Constraints
|
@FFirmenich Thanks for letting me know. I can see how that could make sense. Looking at the above code sample, it feels to me like the error messages are "piece-mealed" (hiding one error behind another), which isn't always that user friendly, but that's completely out of scope for this ticket ;-) |
Describe the bug
When using PHP 8 match() expression, the AssignedComparison validation shows a message, telling that this is not valid.
I don't think this is on purpose as this is the way how match should be used accoding to the PHP docs.
https://www.php.net/manual/de/control-structures.match.php
Code sample
Custom ruleset
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php ...
Expected behavior
No warning. Instead it should be a valid usage of the match expression.
Versions (please complete the following information):
Additional context
none
The text was updated successfully, but these errors were encountered: