Skip to content

Commit

Permalink
no need increment key (#5279)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Nov 23, 2023
1 parent 26f3570 commit 1b12d62
Showing 1 changed file with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,30 +155,24 @@ private function processTextSpacelessInTextNode(
PhpDocTextNode $phpDocTextNode,
Node $currentPhpNode,
int $key
): int {
): void {
$spacelessPhpDocTagNodes = $this->resolveFqnAnnotationSpacelessPhpDocTagNode(
$phpDocTextNode,
$currentPhpNode
);

if ($spacelessPhpDocTagNodes === []) {
return $key;
return;
}

$otherText = Strings::replace($phpDocTextNode->text, self::LONG_ANNOTATION_REGEX, '');
if (! in_array($otherText, ["\n", ""], true)) {
$phpDocNode->children[$key] = new PhpDocTextNode($otherText);
array_splice($phpDocNode->children, $key + 1, 0, $spacelessPhpDocTagNodes);

$key += count($spacelessPhpDocTagNodes);
} else {
unset($phpDocNode->children[$key]);
array_splice($phpDocNode->children, $key, 0, $spacelessPhpDocTagNodes);

$key += count($spacelessPhpDocTagNodes) - 1;
}

return $key;
}

private function transformGenericTagValueNodesToDoctrineAnnotationTagValueNodes(
Expand All @@ -188,7 +182,7 @@ private function transformGenericTagValueNodesToDoctrineAnnotationTagValueNodes(
foreach ($phpDocNode->children as $key => $phpDocChildNode) {
// the @\FQN use case
if ($phpDocChildNode instanceof PhpDocTextNode) {
$key = $this->processTextSpacelessInTextNode($phpDocNode, $phpDocChildNode, $currentPhpNode, $key);
$this->processTextSpacelessInTextNode($phpDocNode, $phpDocChildNode, $currentPhpNode, $key);
continue;
}

Expand All @@ -197,7 +191,7 @@ private function transformGenericTagValueNodesToDoctrineAnnotationTagValueNodes(
}

if (! $phpDocChildNode->value instanceof GenericTagValueNode) {
$key = $this->processDescriptionAsSpacelessPhpDoctagNode(
$this->processDescriptionAsSpacelessPhpDoctagNode(
$phpDocNode,
$phpDocChildNode,
$currentPhpNode,
Expand Down Expand Up @@ -243,20 +237,20 @@ private function processDescriptionAsSpacelessPhpDoctagNode(
PhpDocTagNode $phpDocTagNode,
Node $currentPhpNode,
int $key
): int {
): void {
if (! property_exists($phpDocTagNode->value, 'description')) {
return $key;
return;
}

$description = (string) $phpDocTagNode->value->description;
if (! str_contains($description, "\n")) {
return $key;
return;
}

$phpDocTextNode = new PhpDocTextNode($description);
$startAndEnd = $phpDocTagNode->value->getAttribute(PhpDocAttributeKey::START_AND_END);
if (! $startAndEnd instanceof StartAndEnd) {
return $key;
return;
}

$phpDocTextNode->setAttribute(PhpDocAttributeKey::START_AND_END, $startAndEnd);
Expand All @@ -266,7 +260,7 @@ private function processDescriptionAsSpacelessPhpDoctagNode(
);

if ($spacelessPhpDocTagNodes === []) {
return $key;
return;
}

while (isset($phpDocNode->children[$key]) && $phpDocNode->children[$key] !== $phpDocTagNode) {
Expand All @@ -283,8 +277,6 @@ private function processDescriptionAsSpacelessPhpDoctagNode(
$phpDocNode->children[$key] = $classNode;

array_splice($phpDocNode->children, $key + 1, 0, $spacelessPhpDocTagNodes);

return $key + count($spacelessPhpDocTagNodes);
}

/**
Expand Down

0 comments on commit 1b12d62

Please sign in to comment.