【问题标题】:PSALM: Docblock-defined class or interface does not existPSALM:Docblock 定义的类或接口不存在
【发布时间】:2021-02-06 11:16:05
【问题描述】:

我有以下代码:

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;
    }
}

可能我错过了一些东西,但@psalm-param 出现以下错误:

诗篇:UndefinedDocblockClass:Docblock定义的类或接口Some\Space\Utility\T不存在

【问题讨论】:

    标签: php static-code-analysis psalm-php


    【解决方案1】:

    问题是函数是静态的。这是正确的解决方案:

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

    模板必须在方法上定义。

    【讨论】:

      猜你喜欢
      • 2017-03-22
      • 2018-09-16
      • 1970-01-01
      • 2023-02-07
      • 2014-09-20
      • 1970-01-01
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多