phpinspectionsea
phpinspectionsea copied to clipboard
Wrong 'overrides value' error notification with try/catch in switch
Subject | Details |
---|---|
Plugin | Php Inspections (EA Ultimate), 2021.5 |
Language level | PHP 7.4 |
Current behaviour
In the code below, the "case 0" will never fall through to case 1 (and EA recognizes this, since a "break" is met with a "unreachable statement" notification).
Nonetheless, the first statement of case 1 is considered as affected by a fallthrough from the previous case if "break" is omitted.
So, the correct code gets an error notification, a (slightly incorrect) code gets a warning.
<?php
function test(int $testValue): int {
switch ($testValue) {
case 0:
$value = $testValue;
try {
// Either I return here...
return 1 + $value;
}
catch (Exception $e) {
// ...or I return here.
return 0;
}
// I will never come here.
// break; // <-- If uncommented, this is marked as "Unreachable statement". This is correct
case 1:
$value = 2; // <-- if the BREAK is commented, I get "Overrides value from a preceding case (perhaps a 'break' is missing there).
break;
// throw new RuntimeException("x");
default:
$value = 3;
}
return $value;
}
Expected behaviour
No warning should be issued.
Environment details
Information from Help - About dialog