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

Container::getComponents() returns incorrect type #141

Open
jtojnar opened this issue May 17, 2024 · 3 comments
Open

Container::getComponents() returns incorrect type #141

jtojnar opened this issue May 17, 2024 · 3 comments

Comments

@jtojnar
Copy link

jtojnar commented May 17, 2024

component-model 3.1.0 returns array Container::getComponents() when $deep === false:

nette/component-model@7f613ee

instead of Iterator:

* @phpstan-return ($filterType is null ? \Iterator<int|string, \Nette\ComponentModel\IComponent> : \Iterator<int|string, T>)
*/
public function getComponents(bool $deep = false, string $filterType = null): \Iterator

The return type should be something like

@phpstan-return (
    $deep is true
    ? ($filterType is null ? array<int|string, \Nette\ComponentModel\IComponent> : array<int|string, T>)
    : ($filterType is null ? \Iterator<int|string, \Nette\ComponentModel\IComponent> : \Iterator<int|string, T>)
)

I can open a PR but not sure what to do about older versions. Should I just add conflict with < 3.1.0?

@jtojnar
Copy link
Author

jtojnar commented May 17, 2024

Or maybe we should even remove the stub since the arguments were deprecated in 3.1.0 and Nette has correct annotations for argument-less use.

@ondrejmirtes
Copy link
Member

You can detect which version of Nette the project uses. This has similar approach: https://github.com/phpstan/phpstan-doctrine/blob/4058fdc7333cb9e46f8cf5b952cd9cb59658f2e5/src/Stubs/Doctrine/StubFilesExtensionLoader.php#L75-L84

@jtojnar
Copy link
Author

jtojnar commented May 18, 2024

Thanks for the pointer, I opened #142

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

No branches or pull requests

2 participants