diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php index 480f4e06ace..1f8803faa32 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php @@ -6,12 +6,11 @@ use Iterator; use Nette\Utils\FileSystem; -use PhpParser\BuilderFactory; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; -use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Nop; use PhpParser\Node\Stmt\Property; +use PhpParser\Node\Stmt\PropertyProperty; use PHPUnit\Framework\Attributes\DataProvider; use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Class_\SomeEntityClass; use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\TableClass; @@ -19,8 +18,6 @@ final class MultilineTest extends AbstractPhpDocInfoPrinterTestCase { #[DataProvider('provideData')] - #[DataProvider('provideDataForProperty')] - #[DataProvider('provideDataClass')] public function test(string $docFilePath, Node $node): void { $docComment = FileSystem::read($docFilePath); @@ -32,52 +29,22 @@ public function test(string $docFilePath, Node $node): void public static function provideData(): Iterator { - yield [__DIR__ . '/Source/Multiline/multiline1.txt', new Nop()]; yield [__DIR__ . '/Source/Multiline/multiline2.txt', new Nop()]; yield [__DIR__ . '/Source/Multiline/multiline3.txt', new Nop()]; - } - /** - * @return Iterator - */ - public static function provideDataClass(): Iterator - { + // class yield [__DIR__ . '/Source/Class_/some_entity_class.txt', new Class_(SomeEntityClass::class)]; yield [__DIR__ . '/Source/Multiline/table.txt', new Class_(TableClass::class)]; - } - public static function provideDataForProperty(): Iterator - { - $property = self::createPublicPropertyUnderClass('manyTo'); - yield [__DIR__ . '/Source/Multiline/many_to.txt', $property]; - - $property = self::createPublicPropertyUnderClass('anotherProperty'); + $property = self::createPublicProperty('anotherProperty'); yield [__DIR__ . '/Source/Multiline/assert_serialize.txt', $property]; - $property = self::createPublicPropertyUnderClass('someProperty'); + $property = self::createPublicProperty('someProperty'); yield [__DIR__ . '/Source/Multiline/multiline6.txt', $property]; - - $property = self::createMethodUnderClass('someMethod'); - yield [__DIR__ . '/Source/Multiline/route_property.txt', $property]; } - private static function createPublicPropertyUnderClass(string $name): Property + private static function createPublicProperty(string $name): Property { - $builderFactory = new BuilderFactory(); - - $propertyBuilder = $builderFactory->property($name); - $propertyBuilder->makePublic(); - - return $propertyBuilder->getNode(); - } - - private static function createMethodUnderClass(string $name): ClassMethod - { - $builderFactory = new BuilderFactory(); - - $methodBuilder = $builderFactory->method($name); - $methodBuilder->makePublic(); - - return $methodBuilder->getNode(); + return new Property(Class_::MODIFIER_PUBLIC, [new PropertyProperty($name)]); } } diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/many_to.txt b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/many_to.txt deleted file mode 100644 index cf246d44df4..00000000000 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/many_to.txt +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @var Collection - * @ORM\OneToMany(targetEntity="Spaceflow\Api\Reservation\Entity\Reservation", mappedBy="amenity", cascade={"persist", "merge"}) - * @Serializer\Type("int") - * @Assert\Range( - * min = 0, - * max = 2629744 - * ) - * @Assert\Url( - * protocols = {"https"} - * ) - */ diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/multiline1.txt b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/multiline1.txt deleted file mode 100644 index a43cae180bc..00000000000 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/multiline1.txt +++ /dev/null @@ -1,4 +0,0 @@ -/** - * This is just text - * why is this missing asterisk? - */ diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/route_property.txt b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/route_property.txt deleted file mode 100644 index b75c793c5c9..00000000000 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/route_property.txt +++ /dev/null @@ -1,7 +0,0 @@ -/** - * @Route( - * "/{arg1}/{arg2}", - * defaults={"arg1"=null, "arg2"=""}, - * requirements={"arg1"="\d+", "arg2"=".*"} - * ) - */ diff --git a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php index b96290cc791..c81781aa417 100644 --- a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php +++ b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php @@ -4,7 +4,6 @@ namespace Rector\BetterPhpDocParser\PhpDocInfo; -use PhpParser\Comment; use PhpParser\Comment\Doc; use PhpParser\Node; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; @@ -77,15 +76,7 @@ public function createFromNode(Node $node): ?PhpDocInfo $tokenIterator = new BetterTokenIterator([]); $phpDocNode = new PhpDocNode([]); } else { - $comments = $node->getComments(); - $docs = array_filter($comments, static fn (Comment $comment): bool => $comment instanceof Doc); - - if (count($docs) > 1) { - $this->storePreviousDocs($node, $comments, $docComment); - } - - $text = $docComment->getText(); - $tokens = $this->lexer->tokenize($text); + $tokens = $this->lexer->tokenize($docComment->getText()); $tokenIterator = new BetterTokenIterator($tokens); $phpDocNode = $this->betterPhpDocParser->parse($tokenIterator); @@ -115,48 +106,6 @@ public function createEmpty(Node $node): PhpDocInfo return $phpDocInfo; } - /** - * @param Comment[]|Doc[] $comments - */ - private function storePreviousDocs(Node $node, array $comments, Doc $doc): void - { - $previousDocsAsComments = []; - $newMainDoc = null; - - foreach ($comments as $comment) { - // On last Doc, stop - if ($comment === $doc) { - break; - } - - // pure comment - if (! $comment instanceof Doc) { - $previousDocsAsComments[] = $comment; - continue; - } - - // make Doc as comment Doc that not last - $previousDocsAsComments[] = new Comment( - $comment->getText(), - $comment->getStartLine(), - $comment->getStartFilePos(), - $comment->getStartTokenPos(), - $comment->getEndLine(), - $comment->getEndFilePos(), - $comment->getEndTokenPos() - ); - - /** - * Make last Doc before main Doc to candidate main Doc - * so it can immediatelly be used as replacement of Main doc when main doc removed - */ - $newMainDoc = $comment; - } - - $node->setAttribute(AttributeKey::PREVIOUS_DOCS_AS_COMMENTS, $previousDocsAsComments); - $node->setAttribute(AttributeKey::NEW_MAIN_DOC, $newMainDoc); - } - /** * Needed for printing */ diff --git a/packages/Comments/NodeDocBlock/DocBlockUpdater.php b/packages/Comments/NodeDocBlock/DocBlockUpdater.php index 676ae64a232..7ce8b5bebc8 100644 --- a/packages/Comments/NodeDocBlock/DocBlockUpdater.php +++ b/packages/Comments/NodeDocBlock/DocBlockUpdater.php @@ -58,18 +58,6 @@ public function updateRefactoredNodeWithPhpDocInfo(Node $node): void private function setCommentsAttribute(Node $node): void { - if ($node->hasAttribute(AttributeKey::PREVIOUS_DOCS_AS_COMMENTS)) { - /** @var Comment[] $previousDocsAsComments */ - $previousDocsAsComments = $node->getAttribute(AttributeKey::PREVIOUS_DOCS_AS_COMMENTS); - $node->setAttribute(AttributeKey::COMMENTS, $previousDocsAsComments); - } - - if ($node->hasAttribute(AttributeKey::NEW_MAIN_DOC)) { - /** @var Doc $newMainDoc */ - $newMainDoc = $node->getAttribute(AttributeKey::NEW_MAIN_DOC); - $node->setDocComment($newMainDoc); - } - $comments = array_filter($node->getComments(), static fn (Comment $comment): bool => ! $comment instanceof Doc); $node->setAttribute(AttributeKey::COMMENTS, $comments); } diff --git a/packages/NodeTypeResolver/Node/AttributeKey.php b/packages/NodeTypeResolver/Node/AttributeKey.php index 30dddcea01f..b76a244f576 100644 --- a/packages/NodeTypeResolver/Node/AttributeKey.php +++ b/packages/NodeTypeResolver/Node/AttributeKey.php @@ -44,18 +44,6 @@ final class AttributeKey */ public const COMMENTS = 'comments'; - /** - * Cover multi docs - * @var string - */ - public const PREVIOUS_DOCS_AS_COMMENTS = 'previous_docs_as_comments'; - - /** - * Cover multi docs - * @var string - */ - public const NEW_MAIN_DOC = 'new_main_doc'; - /** * Internal php-parser name. * Do not change this even if you want! diff --git a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector/Fixture/do_not_remove_multiple_docblock_comment.php.inc b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector/Fixture/do_not_remove_multiple_docblock_comment.php.inc deleted file mode 100644 index 9f33c8ca524..00000000000 --- a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector/Fixture/do_not_remove_multiple_docblock_comment.php.inc +++ /dev/null @@ -1,44 +0,0 @@ -property = new \DateTime(); - } -} - -?> ------ -property = new \DateTime(); - } -} - -?> diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index 57781023c5b..057d44b6c94 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -295,8 +295,12 @@ protected function mirrorComments(Node $newNode, Node $oldNode): void /** * @param Node|Node[] $refactoredNode */ - private function postRefactorProcess(Node $originalNode, Node $node, Node|array|int $refactoredNode, string $filePath): Node - { + private function postRefactorProcess( + Node $originalNode, + Node $node, + Node|array|int $refactoredNode, + string $filePath + ): Node { /** @var non-empty-array|Node $refactoredNode */ $this->createdByRuleDecorator->decorate($refactoredNode, $originalNode, static::class);