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
The problem was that the function is static. This is the correct solution:
The template has to be defined on the method.