[EA] This condition ist duplicated in another if/elseif branch
I'm confused.
I want to cleanup my code and get the following suggestion form PhPStorm:
"[EA] This condition ist duplicated in another if/elseif branch"
The statement is:
if($nof !== '' && $not === '')
{
$tab->where .= " and no = '".$nof."'";
}
elseif($nof !== '' && $not !== '')
{
$tab->where .= " and no >= '".$nof."' and no <= '".$not."'";
}
What am I missing?
Please sign in to leave a comment.
Hi there,
This inspection comes from custom Php Inspection (EA Extended) plugin -- please report your concerns to the plugin author: https://github.com/kalessil/phpinspectionsea/issues
But speaking overall, you have the same condition $nof !== '' repeated in both statements. Depends on your code (you showed only 2 conditions) it may have sense to extract that condition to the higher level, e.g. something like this:
if ($nof !== '') {if ($not === '') {
$tab->where .= " and no = '" . $nof . "'";
}
elseif ($not !== '') {
$tab->where .= " and no >= '" . $nof . "' and no <= '" . $not . "'";
}
}