KnpMenu icon indicating copy to clipboard operation
KnpMenu copied to clipboard

Fix phpstan issue

Open raziel057 opened this issue 3 years ago • 1 comments

Currently when creating a RecursiveItemIterator passing a new ArrayIterator, the Iterator is indexed by int.

$treeIterator = new \RecursiveIteratorIterator(
            new RecursiveItemIterator(
                new \ArrayIterator(array($menu))
            ), \RecursiveIteratorIterator::SELF_FIRST
        );

So we got the following error:

Parameter #1 $iterator of class Knp\Menu\Iterator\RecursiveItemIterator constructor expects
Traversable<string, Knp\Menu\ItemInterface>, ArrayIterator<int, Knp\Menu\ItemInterface> given.

I can notice that the typehint in CurrentItemFilterIterator is ok: https://github.com/KnpLabs/KnpMenu/blob/master/src/Knp/Menu/Iterator/CurrentItemFilterIterator.php

raziel057 avatar May 24 '22 13:05 raziel057

This should then update the @extends and @implements, as the key type will be the one of the inner iterator. And the best way to solve it is by making it generic using TKey, reflecting that the original keys are preserved.

passing a new ArrayIterator, the Iterator is indexed by int.

this actually depends whether your array is indexed by int or by string

stof avatar May 24 '22 14:05 stof