Code Inspection: 'if' with common parts
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.
if ($myVar) {
echo $message;
exampleFunction();
} else {
echo $error;
exampleFunction();
}
if ($a) {
echo $message;
} else {
echo $error;
}
exampleFunction();
Suppress an inspection in the editor
Place 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: 25 March 2024