O
O
OnlyMyQuestion2020-06-10 08:00:48
phpstorm
OnlyMyQuestion, 2020-06-10 08:00:48

Why did phpstorm stop checking the return type from phpdoc when implementing an interface that returns an array?

Good afternoon. Problem Example:

class Entity
{

}

interface IFace
{
    /**
     * @return Entity[]
     */
    public function get(): array;
}

class DTO
{

}

interface Repo
{
    /**
     * @return DTO[]
     */
    public function get(): array;
}

class Impl implements IFace
{
    private Repo $repo;

    public function __construct(Repo $repo)
    {
        $this->repo = $repo;
    }

    /**
     * @return Entity[]
     */
    public function get(): array
    {
        return $this->repo->get();
    }
}


The Impl::get method is not highlighted as incorrect.
If we remove IFace and Impl array from the return type:
class Entity
{

}

interface IFace
{
    /**
     * @return Entity[]
     */
    public function get();
}

class DTO
{

}

interface Repo
{
    /**
     * @return DTO[]
     */
    public function get(): array;
}

class Impl implements IFace
{
    private Repo $repo;

    public function __construct(Repo $repo)
    {
        $this->repo = $repo;
    }

    /**
     * @return Entity[]
     */
    public function get()
    {
        return $this->repo->get();
    }
}

Everything lights up correctly.
Previously, such a problem was not observed, I did not notice how it appeared, I did not change the settings, all updates were installed automatically. Tried to reset settings, create another project - nothing has changed.
Is it possible to decide?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sundukov, 2020-06-10
@alekciy

It will probably only be possible to solve it by sending feedback to the developers. In general, it is clear how it happened. Changed language level typing priority over docblock types.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question