Skip to content

@method annotation type overriding #943

Closed
@HEKET313

Description

@HEKET313

Summary of a problem

@method annotation does not override return type of parent method.

Code snippet that reproduces the problem

I have abstract class which implements \Iterator interface and realizes method current

abstract class PayloadCollectionEvent implements \Iterator {
    // Some inner collection which also implements \Iterator
    protected $items;

    // Other \Iterator methods

    /**
     * @inheritdoc
     * @return PayloadInterface
     */
    public function current()
    {
        return $this->items->current();
    }
}

Also I have child class that have annotation @method which override reutrn type of method current()

/**
 * @method ProductUpdateResponse current()
 */
class ProductBatchUpdateResponseEvent extends PayloadCollectionEvent
{
}

PHPStorm understands that now in foreach loop item has type ProductUpdateResponse (which implements PayloadInterface) not PayloadInterface but PHPStan still recognizes it as PayloadInterface

Expected output

I expect that PHPStan will recognize that this method should return new type.

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