如何理解此PHPSTAN错误(具有参数$ asttreedata,而没有在Itable类型阵列中指定的值类型。)
假设我具有这样的格式函数:
function prepareValue(mixed $value): string
{
...
return "{$value}";
}
/**
* @param array<int, array> $astTreeData
* @return string
*/
function makeFormattedDiff(array $astTreeData): string
{
$statusTree = [
'added' => function (string $path, array $node) {
{some code...}
return "Property '{$path}' was added with value: {$value}";
},
'deleted' => fn($path) => "Property '{$path}' was removed",
'nested' => function (string $path, array $node, callable $iterRender) {
{some code...}
return $iterRender($children, $path);
},
'changed' => function (string $path, array $node) {
{some code...}
return "Property '{$path}' was updated. From {$valueBefore} to {$valueAfter}";
},
'unchanged' => fn() => [],
];
/**
* @param array<int, array> $diff
* @return string
*/
$renderPlainDiff = function (array $diff, string|bool $pathComposition) use (&$renderPlainDiff, $statusTree) {
$diffCopy = $diff;
$lines = array_reduce(
$diffCopy,
/**
* @param array<int, string> $acc
* @param array<string, array> $node
* @param array|null $initial
* @return array
*/
function (array $acc, array $node, array|null $initial = []) use (
$renderPlainDiff,
$pathComposition,
$statusTree
) {
{some code...}
$diffTypeHandler = $statusTree[$status];
return flatten([$acc, $diffTypeHandler($newPath, $node, $renderPlainDiff)]);
},
[]
);
return implode("\n", $lines);
};
return $renderPlainDiff($astTreeData, false);
}
所有参数和返回值均用phpdoc详细指定,键入提示语法,但是phpstan给出了一个错误消息phpstan:函数差异\ formatters \ plainformatter \ plainformatter \ plainformatter \ make formatteddiff()具有parameter $ asttreedata with with parameter $ asttreedata with paramtreet $ asttreedata。在Iterable类型数组中没有指定的值类型
需要描述哪些迭代类型数组值?
Say I have a formatter function like this:
function prepareValue(mixed $value): string
{
...
return "{$value}";
}
/**
* @param array<int, array> $astTreeData
* @return string
*/
function makeFormattedDiff(array $astTreeData): string
{
$statusTree = [
'added' => function (string $path, array $node) {
{some code...}
return "Property '{$path}' was added with value: {$value}";
},
'deleted' => fn($path) => "Property '{$path}' was removed",
'nested' => function (string $path, array $node, callable $iterRender) {
{some code...}
return $iterRender($children, $path);
},
'changed' => function (string $path, array $node) {
{some code...}
return "Property '{$path}' was updated. From {$valueBefore} to {$valueAfter}";
},
'unchanged' => fn() => [],
];
/**
* @param array<int, array> $diff
* @return string
*/
$renderPlainDiff = function (array $diff, string|bool $pathComposition) use (&$renderPlainDiff, $statusTree) {
$diffCopy = $diff;
$lines = array_reduce(
$diffCopy,
/**
* @param array<int, string> $acc
* @param array<string, array> $node
* @param array|null $initial
* @return array
*/
function (array $acc, array $node, array|null $initial = []) use (
$renderPlainDiff,
$pathComposition,
$statusTree
) {
{some code...}
$diffTypeHandler = $statusTree[$status];
return flatten([$acc, $diffTypeHandler($newPath, $node, $renderPlainDiff)]);
},
[]
);
return implode("\n", $lines);
};
return $renderPlainDiff($astTreeData, false);
}
All parameters and return values are specified in detail with phpdoc and type hinting syntax but phpStan gives an error message phpstan: Function Differ\Formatters\plainFormatter\makeFormattedDiff() has parameter $astTreeData with no value type specified in iterable type array
What iterable type array values need to be described?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论