From 97a6abd823c158a7b79003068cf22592f91508ac Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 13 Feb 2022 22:38:38 +0100 Subject: [PATCH] don't anonymize call to count to allow assertions on count to be retrieved --- .../Statements/Expression/MatchAnalyzer.php | 3 ++- tests/MatchTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php index 1b302d42f00..9e5423ae2a0 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php @@ -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]; diff --git a/tests/MatchTest.php b/tests/MatchTest.php index c8ecde0cca2..615b7f69c95 100644 --- a/tests/MatchTest.php +++ b/tests/MatchTest.php @@ -82,6 +82,22 @@ function foo(Foo $value): string { 'ignored_issues' => [], 'php_version' => '8.0' ], + 'MatchWithCount' => [ + 'code' => ' throw new \InvalidArgumentException, + default => $array, + }; + }', + 'assertions' => [], + 'ignored_issues' => [], + 'php_version' => '8.1' + ], ]; }