PSALM: Docblock-defined class or interface does not exist

2.4k views Asked by At

I have the following code:

namespace Some\Space\Utility;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

/**
 * @psalm-template T
 */
class SomeAdapter
{
    /**
     * Some method
     *
     * @psalm-param iterable<int, T> $data
     *
     * @psalm-return Collection<int, T>
     */
    public static function doSomething($data): Collection
    {
        if (is_array($data)) {
            $data = new ArrayCollection($data);
        }

        return $data;
    }
}

Probably I miss something but I got the following error for @psalm-param:

psalm: UndefinedDocblockClass: Docblock-defined class or interface Some\Space\Utility\T does not exist

1

There are 1 answers

0
Zoltán Fekete On BEST ANSWER

The problem was that the function is static. This is the correct solution:

    /**
     * Some method
     *
     * @psalm-template T
     * @psalm-param iterable<int, T> $data
     *
     * @psalm-return Collection<int, T>
     */

The template has to be defined on the method.