我从 psalm 得到这个错误,用于树枝扩展:
错误:InvalidArgument - src/Twig/CartExtension.php:44:17 - Twig\TwigFilter::__construct 的参数 2 需要 callable|null,array{App\Twig\CartExtension&static, string(getOfferDate)} 提供
有问题的代码是:
public function getFilters(): array
{
return [
new TwigFilter(
'get_offer_date',
[$this, 'getOfferDate']
),
];
}
TwigFilter 签名是
/**
* @param callable|null $callable A callable implementing the filter. If null, you need to overwrite the "node_class" option to customize compilation.
*/
public function __construct(string $name, $callable = null, array $options = [])
...
树枝文档推荐这种格式
[$this, 'getOfferDate']
对于可调用的:https ://symfony.com/doc/current/templating/twig_extension.html
我怎样才能修复这个 psalm 错误或告诉 psalm 接受它?