Skip to content

Commit

Permalink
Updated Rector to commit 19b42014a5d00de5181bc2463d4c368c5cf194d7
Browse files Browse the repository at this point in the history
rectorphp/rector-src@19b4201 [AutoImport] Handle multiple @\ after GenericTagValueNode (#5277)
  • Loading branch information
TomasVotruba committed Nov 25, 2023
1 parent c92985c commit a2c4ddd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/BetterPhpDocParser/PhpDoc/ArrayItemNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct($value, $key = null)
public function __toString() : string
{
$value = '';
if ($this->key !== null) {
if ($this->key !== null && !\is_numeric($this->key)) {
$value .= $this->key . '=';
}
if (\is_array($this->value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\BetterPhpDocParser\ValueObject\StartAndEnd;
use Rector\Core\Util\StringUtils;
use RectorPrefix202311\Webmozart\Assert\Assert;
final class DoctrineAnnotationDecorator implements PhpDocNodeDecoratorInterface
{
/**
Expand Down Expand Up @@ -175,12 +176,35 @@ private function transformGenericTagValueNodesToDoctrineAnnotationTagValueNodes(
if (\strpos($fullyQualifiedAnnotationClass, '\\') === \false && !\in_array($fullyQualifiedAnnotationClass, self::ALLOWED_SHORT_ANNOTATIONS, \true)) {
continue;
}
$spacelessPhpDocTagNode = $this->createSpacelessPhpDocTagNode($phpDocChildNode->name, $phpDocChildNode->value, $fullyQualifiedAnnotationClass, $currentPhpNode);
$this->attributeMirrorer->mirror($phpDocChildNode, $spacelessPhpDocTagNode);
while (isset($phpDocNode->children[$key]) && $phpDocNode->children[$key] !== $phpDocChildNode) {
++$key;
}
$phpDocTextNode = new PhpDocTextNode($phpDocChildNode->value->value);
$startAndEnd = $phpDocChildNode->value->getAttribute(PhpDocAttributeKey::START_AND_END);
if (!$startAndEnd instanceof StartAndEnd) {
$spacelessPhpDocTagNode = $this->createSpacelessPhpDocTagNode($phpDocChildNode->name, $phpDocChildNode->value, $fullyQualifiedAnnotationClass, $currentPhpNode);
$this->attributeMirrorer->mirror($phpDocChildNode, $spacelessPhpDocTagNode);
$phpDocNode->children[$key] = $spacelessPhpDocTagNode;
continue;
}
$phpDocTextNode->setAttribute(PhpDocAttributeKey::START_AND_END, $startAndEnd);
$spacelessPhpDocTagNodes = $this->resolveFqnAnnotationSpacelessPhpDocTagNode($phpDocTextNode, $currentPhpNode);
if ($spacelessPhpDocTagNodes === []) {
$spacelessPhpDocTagNode = $this->createSpacelessPhpDocTagNode($phpDocChildNode->name, $phpDocChildNode->value, $fullyQualifiedAnnotationClass, $currentPhpNode);
$this->attributeMirrorer->mirror($phpDocChildNode, $spacelessPhpDocTagNode);
$phpDocNode->children[$key] = $spacelessPhpDocTagNode;
continue;
}
Assert::isAOf($phpDocNode->children[$key], PhpDocTagNode::class);
$texts = \explode("\n@\\", $phpDocChildNode->value->value);
$phpDocNode->children[$key]->value = new GenericTagValueNode($texts[0]);
$phpDocNode->children[$key]->value->setAttribute(PhpDocAttributeKey::START_AND_END, $startAndEnd);
$spacelessPhpDocTagNode = $this->createSpacelessPhpDocTagNode($phpDocNode->children[$key]->name, $phpDocNode->children[$key]->value, $fullyQualifiedAnnotationClass, $currentPhpNode);
$this->attributeMirrorer->mirror($phpDocNode->children[$key], $spacelessPhpDocTagNode);
$phpDocNode->children[$key] = $spacelessPhpDocTagNode;
// require to reprint the generic
$phpDocNode->children[$key]->setAttribute(PhpDocAttributeKey::IS_AFTER_GENERIC, \true);
\array_splice($phpDocNode->children, $key + 1, 0, $spacelessPhpDocTagNodes);
}
}
private function processDescriptionAsSpacelessPhpDoctagNode(PhpDocNode $phpDocNode, PhpDocTagNode $phpDocTagNode, Node $currentPhpNode, int $key) : void
Expand Down
6 changes: 5 additions & 1 deletion packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\PhpDocParser\Lexer\Lexer;
use Rector\BetterPhpDocParser\PhpDoc\SpacelessPhpDocTagNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocNodeVisitor\ChangedPhpDocNodeVisitor;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
Expand Down Expand Up @@ -278,7 +279,10 @@ private function correctPreviouslyReprintedFirstNode(int $key, StartAndEnd $star
private function shouldReprint(PhpDocChildNode $phpDocChildNode) : bool
{
$this->changedPhpDocNodeTraverser->traverse($phpDocChildNode);
return $this->changedPhpDocNodeVisitor->hasChanged();
if ($this->changedPhpDocNodeVisitor->hasChanged()) {
return \true;
}
return $phpDocChildNode instanceof SpacelessPhpDocTagNode && $phpDocChildNode->getAttribute(PhpDocAttributeKey::IS_AFTER_GENERIC) === \true;
}
private function standardPrintPhpDocChildNode(PhpDocChildNode $phpDocChildNode) : string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ final class PhpDocAttributeKey
* @var string
*/
public const ORIG_NODE = NativePhpDocAttributeKey::ORIG_NODE;
/**
* @var string
*/
public const IS_AFTER_GENERIC = 'is_after_generic';
}
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'd864d7b856e7bb8b7e98db96793ceb1036c1bf7b';
public const PACKAGE_VERSION = '19b42014a5d00de5181bc2463d4c368c5cf194d7';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-11-23 16:49:59';
public const RELEASE_DATE = '2023-11-25 08:28:40';
/**
* @var int
*/
Expand Down

0 comments on commit a2c4ddd

Please sign in to comment.