Skip to content

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

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions