Closed
Description
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
<?php
test();
/**
* @return void
*/
function test() {
$food = 'cake';
$returnValue = match (true) {
$food === 'apple' => 'This food is an apple',
$food === 'bar' => 'This food is a bar',
$food === 'cake' => 'This food is a cake',
};
}
Custom ruleset
<?xml version="1.0"?>
<ruleset name="My Custom Standard">
<rule ref="Squiz.PHP.DisallowComparisonAssignment"/>
</ruleset>
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php
with the code sample above... - Run
phpcs test.php ...
- See error message displayed
phpcs: Squiz.PHP.DisallowComparisonAssignment.AssignedComparison: The value of a comparison must not be assigned to a variable
Expected behavior
No warning. Instead it should be a valid usage of the match expression.
Versions (please complete the following information):
- OS: Windows 10
- PHP: 8.1
- PHPCS: 3.7.0
- Standard: Custom
Additional context
none