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

5.2: ResultIterator::getIterator() @method declaration is wrong #258

Open
homersimpsons opened this issue May 6, 2021 · 0 comments
Open

Comments

@homersimpsons
Copy link
Collaborator

Currently 5.2 Generate something like

/**
 * @method Entity[] getIterator()
 */
abstract class EntityResultIterator {

}

This is not really true as the ResultIterator::getIterator() function returns a InnerResultIteratorInterface which is defined as:

interface InnerResultIteratorInterface extends \Traversable, \Countable, \ArrayAccess

I guess the correct way is to type-hint the whole chain following this phpstan template:
https://phpstan.org/r/f87e4ede-1067-4795-bb40-a8eac8b1f7b8

PHPStan Code Sample
<?php declare(strict_types = 1);

/**
* @template T
*
* @extends Traversable<mixed, T>
* @extends ArrayAccess<mixed, T>
*/
interface HelloWorld extends Countable, Traversable, ArrayAccess
{
}

/**
* @template T
*/
abstract class ATest {
   /**
    * @return HelloWorld<T>
    */
   abstract function getIterator(): HelloWorld;
}

/**
* @extends ATest<Entity>
*/
class Test extends ATest {}

class Entity {}

/cc @dsavina

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

1 participant