Closed
Description
Describe the bug
When I uses match-expression
inside a switch-case
, I get non logical error
Code sample
switch ($appEnv) {
case 'production':
return ($foo == 'bar') ? 'prod' : 'production';
case 'staging':
return match ($foo) {
'bar' => 'custom_1',
'baz' => 'custom_2',
default => 'staging'
};
case 'testing':
return 'testing';
default:
return 'default';
}
I get error starting from the line "case 'testing': .....'
Error: Line indented incorrectly; expected 12 spaces, found 8
This require me to justify the "case 'testing':" with its body and "default:" case with its body to closing curly brace of match expression!
Like this:
switch ($appEnv) {
case 'production':
return ($foo == 'bar') ? 'prod' : 'production';
case 'staging':
return match ($foo) {
'bar' => 'custom_1',
'baz' => 'custom_2',
default => 'staging'
};
case 'testing':
return 'testing';
default:
return 'default';
}
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 output here
Expected behavior
A clear and concise description of what you expected to happen.
Versions (please complete the following information):
- OS: Linux 050918c5cfc1 5.11.0-43-generic ~ 20.04.2-Ubuntu SMP x86_64
- PHP: 8.0.13
- PHPCS: 3.6.1 stable
- Standard: PSR2