diff --git a/examples/TemplateChecker.php b/examples/TemplateChecker.php index ddaaab2baab..c44334d85a7 100644 --- a/examples/TemplateChecker.php +++ b/examples/TemplateChecker.php @@ -61,7 +61,7 @@ public function analyze(?Context $file_context = null, ?Context $global_context throw new InvalidArgumentException('Could not interpret doc comment correctly'); } - /** @psalm-suppress ArgumentTypeCoercion */ + /** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */ $method_id = new MethodIdentifier(...explode('::', $matches[1])); $this_params = $this->checkMethod($method_id, $first_stmt, $codebase); diff --git a/examples/plugins/FunctionCasingChecker.php b/examples/plugins/FunctionCasingChecker.php index f4147ab3f3f..8cffc2184ed 100644 --- a/examples/plugins/FunctionCasingChecker.php +++ b/examples/plugins/FunctionCasingChecker.php @@ -34,7 +34,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve } try { - /** @psalm-suppress ArgumentTypeCoercion */ + /** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */ $method_id = new MethodIdentifier(...explode('::', $declaring_method_id)); $function_storage = $codebase->methods->getStorage($method_id); diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index a02f61403f6..14cbf71b88a 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -958,7 +958,7 @@ public function getFunctionStorageForSymbol(string $file_path, string $symbol): { if (strpos($symbol, '::')) { $symbol = substr($symbol, 0, -2); - /** @psalm-suppress ArgumentTypeCoercion */ + /** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */ $method_id = new MethodIdentifier(...explode('::', $symbol)); $declaring_method_id = $this->methods->getDeclaringMethodId($method_id); @@ -1007,7 +1007,7 @@ public function getMarkupContentForSymbolByReference( if (strpos($reference->symbol, '()')) { $symbol = substr($reference->symbol, 0, -2); - /** @psalm-suppress ArgumentTypeCoercion */ + /** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */ $method_id = new MethodIdentifier(...explode('::', $symbol)); $declaring_method_id = $this->methods->getDeclaringMethodId( @@ -1216,7 +1216,7 @@ public function getSymbolInformation(string $file_path, string $symbol): ?array if (strpos($symbol, '()')) { $symbol = substr($symbol, 0, -2); - /** @psalm-suppress ArgumentTypeCoercion */ + /** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */ $method_id = new MethodIdentifier(...explode('::', $symbol)); $declaring_method_id = $this->methods->getDeclaringMethodId($method_id); @@ -1359,7 +1359,7 @@ public function getSymbolLocation(string $file_path, string $symbol): ?CodeLocat if (strpos($symbol, '()')) { $symbol = substr($symbol, 0, -2); - /** @psalm-suppress ArgumentTypeCoercion */ + /** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */ $method_id = new MethodIdentifier(...explode('::', $symbol)); $declaring_method_id = $this->methods->getDeclaringMethodId($method_id); @@ -1445,7 +1445,7 @@ public function getSymbolLocationByReference(Reference $reference): ?CodeLocatio if (strpos($reference->symbol, '()')) { $symbol = substr($reference->symbol, 0, -2); - /** @psalm-suppress ArgumentTypeCoercion */ + /** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */ $method_id = new MethodIdentifier( ...explode('::', $symbol), ); @@ -1656,7 +1656,7 @@ public function getSignatureInformation( $signature_label = ''; $signature_documentation = null; if (strpos($function_symbol, '::') !== false) { - /** @psalm-suppress ArgumentTypeCoercion */ + /** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */ $method_id = new MethodIdentifier(...explode('::', $function_symbol)); $declaring_method_id = $this->methods->getDeclaringMethodId($method_id); diff --git a/src/Psalm/Config/Creator.php b/src/Psalm/Config/Creator.php index a2fe96463a5..6fc2b596cc1 100644 --- a/src/Psalm/Config/Creator.php +++ b/src/Psalm/Config/Creator.php @@ -162,6 +162,7 @@ public static function getLevel(array $issues, int $counted_types): int return array_keys($issues_at_level)[0] + 1; } + /** @psalm-suppress TooFewArguments */ return max(...array_keys($issues_at_level)) + 1; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php index 44b7da23c0b..5a2c6dcc690 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php @@ -818,7 +818,9 @@ public static function checkArgumentsMatch( $args_provided_min += $array_type->count ? ($array_type->count - 1) : 0; } else { - if (isset($array_type->type_params[1]) && $array_type->type_params[1]->isNever()) { + if (isset($array_type->type_params[1]) + && $array_type->type_params[1] instanceof Union + && $array_type->type_params[1]->isNever()) { $args_provided_max--; } else { $args_provided_max = $function_param_count + 10_00_00_00_00; @@ -981,11 +983,12 @@ public static function checkArgumentsMatch( if ($has_unpacked_non_keyed_array && $args_provided_min < $required_args_count && $has_packed_var) { IssueBuffer::maybeAdd( new TooFewArguments( - 'Possibly too few arguments for ' . ($cased_method_id ?: $method_id) + 'Possibly too few arguments for ' + . ($cased_method_id ?? (string) $method_id) . ' - expecting ' . $required_args_count . ' but possibly only' . ' ' . $args_provided_min . ' provided', $code_location, - ($cased_method_id ?: $method_id), + ($cased_method_id ?? (string) $method_id), ), $statements_analyzer->getSuppressedIssues(), ); @@ -996,11 +999,12 @@ public static function checkArgumentsMatch( // as it would often together otherwise IssueBuffer::maybeAdd( new TooManyArguments( - 'Possibly too many arguments for ' . ($cased_method_id ?: $method_id) + 'Possibly too many arguments for ' + . ($cased_method_id ?? (string) $method_id) . ' - expecting ' . $function_param_count . ' but saw' . ' ' . ($args_provided_max > 5000 ? 'unlimited from unpacking' : $args_provided_max), $code_location, - ($cased_method_id ?: $method_id), + ($cased_method_id ?? (string) $method_id), ), $statements_analyzer->getSuppressedIssues(), ); @@ -1307,6 +1311,7 @@ static function ( if ($by_ref_type && $function_param->is_variadic && $arg->unpack) { // string unpacking available since 8.1 if ($codebase->analysis_php_version_id >= 8_01_00 + && $method_id && $codebase->getFunctionLikeStorage($statements_analyzer, $method_id)->allow_named_arg_calls ) { $by_ref_type = new Union([ @@ -1775,7 +1780,8 @@ private static function checkArgCount( ) { IssueBuffer::maybeAdd( new TooManyArguments( - 'Too many arguments for ' . ($cased_method_id ?: $method_id) + 'Too many arguments for ' + . ($cased_method_id ?? (string) $method_id) . ' - expecting ' . count($function_params) . ' but saw ' . count($args), $code_location, (string)$method_id, diff --git a/src/Psalm/Internal/Codebase/ClassLikes.php b/src/Psalm/Internal/Codebase/ClassLikes.php index d65853cfc3b..a28503c46bd 100644 --- a/src/Psalm/Internal/Codebase/ClassLikes.php +++ b/src/Psalm/Internal/Codebase/ClassLikes.php @@ -954,6 +954,9 @@ public function moveMethods(Methods $methods, ?Progress $progress = null): void try { $source_method_storage = $methods->getStorage( + /** + * @psalm-suppress TooFewArguments + */ new MethodIdentifier(...$source_parts), ); } catch (InvalidArgumentException $e) {