Skip to content

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

Open
@homersimpsons

Description

@homersimpsons

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions