Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix phpstan issue #369

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix phpstan issue #369

wants to merge 1 commit into from

Conversation

raziel057
Copy link

@raziel057 raziel057 commented May 24, 2022

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

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

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

So we got the following error:

Parameter KnpLabs#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
@stof
Copy link
Collaborator

stof commented May 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants