Code Inspection: 'if' with common parts
Configure inspections: Settings | Editor | Inspections
Show intention actions: AltEnter
Reports the if
statements with duplicated common parts.
In the following example, both the if
and else
branches of a conditional statement contain the common exampleFunction()
call. After the quick-fix is applied, the call is extracted from the conditional statement.
Initial statement
if ($myVar) { echo $message; exampleFunction();} else { echo $error; exampleFunction();}
Simplified statement
if ($a) { echo $message;} else { echo $error;}exampleFunction();
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.