Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix count with match on arrays #7665

Merged
merged 1 commit into from Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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