Phpinspectionsea: False positive: duplicate condition in if branch

Created on 6 Jul 2017  路  4Comments  路  Source: kalessil/phpinspectionsea

When testing twice the same variable in nested ifs, even if the variable has been overwritten, the inspection reports:

The condition is duplicated in another if/elseif branch.

How to reproduce:

function getUserIdFromSession() { return null; }
function getUserIdFromPermanentSession() { return null; }

function test()
{
    $userId = getUserIdFromSession();

    if ($userId === null) {
        $userId = getUserIdFromPermanentSession();

        if ($userId === null) { // "The condition is duplicated in another if/elseif branch."
            return null;
        }

        // ...
    }

    // ...
}

It would be nice to detect when the variable has been overwritten!

bug / false-positive fixed

All 4 comments

Fixed.

Note: further extension of #306

Thanks, that was fast!

You are welcome =)

Fixed #550, coming into 2.3.12

Was this page helpful?
0 / 5 - 0 ratings