Code Inspection: 'switch' with common parts
Reports the 'switch' statements with duplicated common parts.
In the following example, all branches of the switch
statement contain the common echo $message
statement. After the quick-fix is applied, this statement extracted from the switch
statement.
switch ($a) {
case 1:
echo $message;
doSmth();
break;
case 2:
echo $message;
echo $error;
break;
default:
echo $message;
doSmthElse();
break;
}
echo $message;
switch ($a) {
case 1:
doSmth();
break;
case 2:
echo $error;
break;
default:
doSmthElse();
break;
}
Suppress an inspection in the editor
Position the caret at the highlighted line and press Alt+Enter or click .
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.
Last modified: 16 May 2022