Skip to content

Commit

Permalink
Fix handling phpDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
Wirone committed Dec 25, 2023
1 parent 92232fa commit 691f0df
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Fixer/Import/FullyQualifiedStrictTypesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,16 @@ private function fixPhpDoc(Tokens $tokens, int $index, array $uses, string $name
{
$phpDoc = $tokens[$index];
$phpDocContent = $phpDoc->getContent();
Preg::matchAll('#@([^\s]+)\s+([^\s]+)#', $phpDocContent, $matches);
Preg::matchAll('#@([^\s]+)(\s+)((?:[a-zA-Z0-9_\\\\]+)+)#', $phpDocContent, $matches);

if ([] !== $matches) {
foreach ($matches[2] as $i => $typeName) {
if ([] !== $matches[0]) {
foreach ($matches[3] as $i => $typeName) {
if (!\in_array($matches[1][$i], ['param', 'return', 'see', 'throws', 'var'], true)) {
continue;
}

if (true === $this->configuration['import_symbols'] && isset($matches[2][0])) {
$this->registerSymbolForImport('class', $matches[2][0], $uses, $namespaceName);
if (true === $this->configuration['import_symbols'] && isset($matches[3][0])) {
$this->registerSymbolForImport('class', $matches[3][0], $uses, $namespaceName);
}

$shortTokens = $this->determineShortType($typeName, $uses, $namespaceName);
Expand All @@ -280,16 +280,16 @@ private function fixPhpDoc(Tokens $tokens, int $index, array $uses, string $name
// Replace tag+type in order to avoid replacing type multiple times (when same type is used in multiple places)
$phpDocContent = str_replace(
$matches[0][$i],
'@'.$matches[1][$i].' '.implode('', array_map(
'@'.$matches[1][$i].$matches[2][$i].implode('', array_map(
static fn (Token $token) => $token->getContent(),
$shortTokens
)),
$phpDocContent
);

$tokens[$index] = new Token([T_DOC_COMMENT, $phpDocContent]);
}
}

$tokens[$index] = new Token([T_DOC_COMMENT, $phpDocContent]);
}
}

Expand Down

0 comments on commit 691f0df

Please sign in to comment.