Skip to content

Commit

Permalink
don't anonymize call to count to allow assertions on count to be retr…
Browse files Browse the repository at this point in the history
…ieved
  • Loading branch information
orklah committed Feb 13, 2022
1 parent 59d3d2a commit 97a6abd
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 97a6abd

Please sign in to comment.