Phpinspectionsea: "Foreach source to iterate over" inspection bugged for union types

Created on 1 Nov 2017  路  2Comments  路  Source: kalessil/phpinspectionsea

Given the following code:

    public function x(\Iterable $foo)
    {
        if (!$foo instanceof Foo) {
            throw new \InvalidArgumentException('$foo must also be a Foo.');
        }

        // From this point on $foo is now a union of \Iterable|Foo.
        foreach ($foo as $_) { ; } // "Can not iterate Foo (must implement one of Iterator interfaces)"
    }

Once $foo becomes a union type the inspection fails on the non-iterable type, ignoring the fact that it is still a union of a perfectly valid iterable type.

bug / false-positive fixed

All 2 comments

Fixed

And to clarify: Foo class might be defined still, as it often used in UTs =)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prdatur picture prdatur  路  3Comments

Gamesh picture Gamesh  路  3Comments

raoptimus picture raoptimus  路  3Comments

voku picture voku  路  3Comments

TimothyBJacobs picture TimothyBJacobs  路  3Comments