1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

don't anonymize call to count to allow assertions on count to be retrieved

This commit is contained in:
orklah 2022-02-13 22:38:38 +01:00
parent 59d3d2aa31
commit 97a6abd823
2 changed files with 18 additions and 1 deletions

View File

@ -79,7 +79,8 @@ class MatchAnalyzer
&& $stmt->cond->name instanceof PhpParser\Node\Name
&& ($stmt->cond->name->parts === ['get_class']
|| $stmt->cond->name->parts === ['gettype']
|| $stmt->cond->name->parts === ['get_debug_type'])
|| $stmt->cond->name->parts === ['get_debug_type']
|| $stmt->cond->name->parts === ['count'])
&& $stmt->cond->getArgs()
) {
$first_arg = $stmt->cond->getArgs()[0];

View File

@ -82,6 +82,22 @@ class MatchTest extends TestCase
'ignored_issues' => [],
'php_version' => '8.0'
],
'MatchWithCount' => [
'code' => '<?php
/**
* @return non-empty-array
*/
function test(array $array): array
{
return match (\count($array)) {
0 => throw new \InvalidArgumentException,
default => $array,
};
}',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.1'
],
];
}