Code Inspection: Condition always evaluates to 'true/false'
Configure inspections: Settings | Editor | Inspections
Show intention actions: AltEnter
Reports the conditions that are already covered by earlier conditions and thus have no effect as well as the variables that are always true (or always false) when reached.
In the following example, in case $var
is an instance of the SomeClass
class, then it automatically means that it is not null
. As a result, the subsequent $var === null
condition always resolves to true
and is therefore redundant. After the quick-fix is applied, the redundant condition is removed.
Before the quick-fix
if ($var instanceof SomeClass) { if ($var === null) { echo $errorMsg; } echo $msg;}
After the quick-fix
if ($var instanceof SomeClass) { echo $msg;}
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.