Phpinspectionsea: This condition is duplicated in another if/elseif branch

Created on 22 Sep 2017  路  6Comments  路  Source: kalessil/phpinspectionsea

$file = 'text_new.html';
if (!is_file($file)) {
  $file = 'text_old.html';
  if (!is_file($file)) { // <-- error
    $file = 'text_fallback.html';
  }
}

Hello. I refactor some legacy code. And here is what I find.
When we check variable, then modify it, and then check again - we get false-positive.

bug / false-positive fixed

All 6 comments

Oh noeeeeesssss, my beloved case =)
May I ask you to cross-link similar issues here, so I would know which functions to handle in a special way please?

@kalessil sure. If I find some similar I will post it.

Similar issues: #381, #339, #289.

I can confirm this. This is part of my legacy code in case it helps developing a solution:

<?php
$sVariante = $aLine[$this->getIndexOfColumnInArticlesCsv('attr_artikel_var_laufzeit')];
 if ($sVariante != null && strlen(trim($sVariante)) > 0)
{
    // ...
}
else
{
    $sVariante = $aLine[$this->getIndexOfColumnInArticlesCsv('attr_artikel_var_user')];
    if ($sVariante != null && strlen(trim($sVariante)) > 0)
    {
        // ...
    }
}

Hopefully, I'll deal with the issue in this release.

Fixed!

Was this page helpful?
0 / 5 - 0 ratings