Container::getComponents() returns incorrect type

Open
#141 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
php
Domain
devtools

Research direction

Start with stubs/ComponentModel/Container.stub and compare its declared return type with the component-model 3.1.0 behavior shown in commit 7f613eed7f5e57b6bde2d0be1bfdbb7e161620b3. Determine how older component-model versions should be handled, then update the conditional return type so shallow and deep calls match their actual results and verify the compatibility behavior.

Written by the indexing model from the issue text.

Description

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

https://github.com/nette/component-model/commit/7f613eed7f5e57b6bde2d0be1bfdbb7e161620b3

instead of Iterator:

https://github.com/phpstan/phpstan-nette/blob/8af94743efcc6d1e685f2ffd7ab279e39c96429c/stubs/ComponentModel/Container.stub#L11-L13

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?

Dominant language
PHP
Stars
118
Forks
44
Avg merge
17d 5h
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpstan/phpstan-nette

All issues in phpstan/phpstan-nette

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.