Skip to content

Commit

Permalink
Merge pull request #7665 from orklah/matchcount
Browse files Browse the repository at this point in the history
fix count with match on arrays
  • Loading branch information
orklah committed Feb 13, 2022
2 parents 8a49cac + 97a6abd commit b796f45
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -79,7 +79,8 @@ public static function analyze(
&& $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];
Expand Down
16 changes: 16 additions & 0 deletions tests/MatchTest.php
Expand Up @@ -82,6 +82,22 @@ function foo(Foo $value): string {
'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'
],
];
}

Expand Down

0 comments on commit b796f45

Please sign in to comment.