From 579757ad50aa108e8a58282682d3e3aabbe2b3df Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Tue, 11 Jun 2024 20:54:35 +0200 Subject: [PATCH] allow multiple phpstan tags with same name --- src/Visitor.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Visitor.php b/src/Visitor.php index f2bb20d..3a033a8 100644 --- a/src/Visitor.php +++ b/src/Visitor.php @@ -436,21 +436,32 @@ private function getAdditionalTagsFromMap(string $symbolName): array $parameters = $this->functionMap[$symbolName]; $returnType = array_shift($parameters); + /** @var array> $parameters */ + + $otherTags = array_filter( + $parameters, + static function ($paramName): bool { + return strpos($paramName, '@') === 0; + }, + ARRAY_FILTER_USE_KEY + ); + + $parameters = array_diff_key($parameters, $otherTags); /** @var array $parameters */ $additions = []; - foreach ($parameters as $paramName => $paramType) { - if (strpos($paramName, '@') === 0) { - $format = ( $paramType === '' ) ? '%s' : '%s %s'; + foreach ($otherTags as $tagName => $tagValues) { + foreach ((array)$tagValues as $tagValue) { $additions[] = sprintf( - $format, - $paramName, - $paramType + ($tagValue === '') ? '%s' : '%s %s', + $tagName, + $tagValue ); - continue; } + } + foreach ($parameters as $paramName => $paramType) { $additions[] = sprintf( '@phpstan-param %s $%s', $paramType,