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

php-ds: add missed return types for the getIterator() methods #1607

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

HaruAtari
Copy link
Contributor

Image that you have a method which returns a generic collection:

/**
 * @return Vector<Communication>
 */
public function getCollection(): Vector{
  return new Vector([new Communication(), new Communication()]);
}

And also you have another method where you iterate over that collection:

public function test()
{
  $list = $this->getCollection();
  foreach($collection as $item){
    ..
  }
}

If both methods are in the same class, everything works good. But if these classes are in different classes, phpstorm will no understand a time of collection's item inside foreach.

Everything works properly for the Queue collection, but there is problems with other collections. I see that there is a phpdoc for the Queue::getIterator() method:

/**
 * @return Traversable<TValue>
 */
 public function getIterator(): Traversable {}

but there is no such ones for other collection.

So this MR fixes this issue

@isfedorov isfedorov merged commit 8ea3bf4 into JetBrains:master Jan 17, 2024
11 checks passed
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

Successfully merging this pull request may close these issues.

2 participants