忽略phpstan对方法参数的检查:
ignoreErrors:
- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ has parameter \\$[a-zA-Z0-9_]+ with no value type specified in iterable type array#"
- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ return type has no value type specified in iterable type array#"
- "#Property [a-zA-Z0-9\\$\\_\\\\:\\(\\)]+ type has no value type specified in iterable type array#"
参考:https://github.com/phpstan/phpstan/discussions/7287
上面是之前的写法,主要目的是: 想给 $left 和 $right 类型声明,但是 array 值的类型,一直不确定,后来发现可以按下面的方式解决,原来是mixed就可以了,不用添加如上配置
/**
* @param array<mixed> $left
* @param array<mixed> $right
*/
public function compareByDate($left = [], $right = [], string $order = 'asc'): int
{
$dateLeft = $left['date']->getTimestamp();
$dateRight = $right['date']->getTimestamp();
$result = ($dateLeft < $dateRight) ? -1 : 1;
return ('asc' == $order) ? $result : -$result;
}
