From acf4d1b4f530644abec8ba7e91576ec0f8c40d82 Mon Sep 17 00:00:00 2001 From: rector-bot Date: Mon, 4 May 2020 21:51:47 +0000 Subject: [PATCH] fixup! fixup! fixup! fixup! fixup! Add test case for #3222 --- .../src/PhpDocInfo/PhpDocInfoFactory.php | 29 +++++++++---------- .../NodeAnalyzer/DocBlockManipulator.php | 7 ----- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php b/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php index b0e44607e27..85fc3faef59 100644 --- a/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php +++ b/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php @@ -56,6 +56,15 @@ final class PhpDocInfoFactory * @var ParamPhpDocNodeFactory */ private $paramPhpDocNodeFactory; + // create empty node + /** + * @var string + */ + private const CONTENT = ''; + /** + * @var mixed[] + */ + private const TOKENS = []; public function __construct( PhpDocParser $phpDocParser, @@ -82,14 +91,6 @@ public function createFromNode(Node $node): ?PhpDocInfo if ($node->getDocComment() === null) { return null; - - if ($node->getComments() !== []) { - return null; - } - // create empty node - $content = ''; - $tokens = []; - $phpDocNode = new AttributeAwarePhpDocNode([]); } else { $content = $node->getDocComment()->getText(); $tokens = $this->lexer->tokenize($content); @@ -104,13 +105,9 @@ public function createEmpty(Node $node): PhpDocInfo { /** needed for @see PhpDocNodeFactoryInterface */ $this->currentNodeProvider->setNode($node); - - // create empty node - $content = ''; - $tokens = []; $phpDocNode = new AttributeAwarePhpDocNode([]); - return $this->createFromPhpDocNode($phpDocNode, $content, $tokens, $node); + return $this->createFromPhpDocNode($phpDocNode, self::CONTENT, self::TOKENS, $node); } private function parseTokensToPhpDocNode(array $tokens): AttributeAwarePhpDocNode @@ -142,16 +139,16 @@ private function setPositionOfLastToken(AttributeAwarePhpDocNode $attributeAware } private function createFromPhpDocNode( - AttributeAwarePhpDocNode $phpDocNode, + AttributeAwarePhpDocNode $attributeAwarePhpDocNode, string $content, array $tokens, Node $node ): PhpDocInfo { /** @var AttributeAwarePhpDocNode $phpDocNode */ - $phpDocNode = $this->attributeAwareNodeFactory->createFromNode($phpDocNode, $content); + $attributeAwarePhpDocNode = $this->attributeAwareNodeFactory->createFromNode($attributeAwarePhpDocNode, $content); $phpDocInfo = new PhpDocInfo( - $phpDocNode, + $attributeAwarePhpDocNode, $tokens, $content, $this->staticTypeMapper, diff --git a/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockManipulator.php b/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockManipulator.php index 657bcecfe96..30b7bf0b994 100644 --- a/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockManipulator.php +++ b/packages/node-type-resolver/src/PhpDoc/NodeAnalyzer/DocBlockManipulator.php @@ -99,13 +99,6 @@ public function updateNodeWithPhpDocInfo(Node $node): void if ($phpDoc === '') { dump($phpDocInfo); die; - - if ($phpDocInfo->getOriginalPhpDocNode()->children !== []) { - // all comments were removed → null - $node->setAttribute('comments', null); - } - - return; } // no change, don't save it