Code Inspection: 'switch' with common parts
Configure inspections: Settings | Editor | Inspections
Show intention actions: AltEnter
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.
Initial statement
switch ($a) { case 1: echo $message; doSmth(); break; case 2: echo $message; echo $error; break; default: echo $message; doSmthElse(); break;}
Simplified statement
echo $message;switch ($a) { case 1: doSmth(); break; case 2: echo $error; break; default: doSmthElse(); break;}
Place the caret at the highlighted line and press AltEnter or click
.
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.