Skip to content

Commit 2463982

Browse files
committed
fix: enhance annotation parsing to support multiple values per tag
1 parent 6d11ce6 commit 2463982

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Rules/DocBlockHeaderFixer.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ private function findInsertPosition(Tokens $tokens, int $structureIndex): int
327327
}
328328

329329
/**
330-
* @return array<string, string>
330+
* @return array<string, string|array<string>>
331331
*/
332332
private function parseExistingAnnotations(string $docBlockContent): array
333333
{
@@ -339,15 +339,27 @@ private function parseExistingAnnotations(string $docBlockContent): array
339339
if (preg_match('/^@(\w+)(?:\s+(.*))?$/', $line, $matches)) {
340340
$tag = $matches[1];
341341
$value = $matches[2] ?? '';
342-
$annotations[$tag] = $value;
342+
343+
// If this tag already exists, convert to array or append to existing array
344+
if (isset($annotations[$tag])) {
345+
// Convert existing single value to array
346+
if (!is_array($annotations[$tag])) {
347+
$annotations[$tag] = [$annotations[$tag]];
348+
}
349+
// Append new value to array
350+
$annotations[$tag][] = $value;
351+
} else {
352+
// First occurrence, store as string
353+
$annotations[$tag] = $value;
354+
}
343355
}
344356
}
345357

346358
return $annotations;
347359
}
348360

349361
/**
350-
* @param array<string, string> $existing
362+
* @param array<string, string|array<string>> $existing
351363
* @param array<string, string|array<string>> $new
352364
*
353365
* @return array<string, string|array<string>>

0 commit comments

Comments
 (0)