psalm
psalm copied to clipboard
Unexpected MixedReturnStatement
Example psalm: https://psalm.dev/r/7a1ebb5700
Example phpstam: https://phpstan.org/r/1f5ed47d-410c-4b4e-9c5c-d0506dfb5ec8
I found these snippets:
https://psalm.dev/r/7a1ebb5700
<?php
/**
*
* @template TValue
* @template TResultValue
*
* @param callable(TValue):TResultValue $func
* @param iterable<TValue> $list
*
* @return list<TResultValue>
*/
function list_map(callable $func, iterable $list): iterable
{
$result = [];
foreach($list as $item) {
$result[] = $func($item);
}
return $result;
}
$data = [['name' => 'string']];
$result = list_map(fn (array $value): string => $value['name'], $data);
var_export($result);
Psalm output (using commit ef3b018):
INFO: PossiblyUndefinedStringArrayOffset - 25:49 - Possibly undefined array offset ''name'' is risky given expected type 'array-key'. Consider using isset beforehand.
INFO: MixedReturnStatement - 25:49 - Could not infer a return type