diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index f07357e6436..36748dfb127 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'df8d2b78edd46542e6426fec606c3ea98d712532'; + public const PACKAGE_VERSION = '8d524d4c3b4a8b506d558eec23caf1923e59bb81'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-02-11 15:57:49'; + public const RELEASE_DATE = '2024-02-12 15:43:59'; /** * @var int */ diff --git a/src/PostRector/Rector/UnusedImportRemovingPostRector.php b/src/PostRector/Rector/UnusedImportRemovingPostRector.php index 0121fbda482..62dfa17f15c 100644 --- a/src/PostRector/Rector/UnusedImportRemovingPostRector.php +++ b/src/PostRector/Rector/UnusedImportRemovingPostRector.php @@ -4,6 +4,8 @@ declare (strict_types=1); namespace Rector\PostRector\Rector; use RectorPrefix202402\Nette\Utils\Strings; +use PhpParser\Comment; +use PhpParser\Comment\Doc; use PhpParser\Node; use PhpParser\Node\Identifier; use PhpParser\Node\Name; @@ -101,15 +103,29 @@ final class UnusedImportRemovingPostRector extends \Rector\PostRector\Rector\Abs { $names = []; $this->simpleCallableNodeTraverser->traverseNodesWithCallable($namespace, function (Node $node) use(&$names) { - if (!$node->hasAttribute(AttributeKey::COMMENTS)) { + $comments = $node->getComments(); + if ($comments === []) { return null; } - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); - $names = \array_merge($names, $phpDocInfo->getAnnotationClassNames()); - $constFetchNodeNames = $phpDocInfo->getConstFetchNodeClassNames(); - $names = \array_merge($names, $constFetchNodeNames); - $genericTagClassNames = $phpDocInfo->getGenericTagClassNames(); - $names = \array_merge($names, $genericTagClassNames); + $docs = \array_filter($comments, static function (Comment $comment) : bool { + return $comment instanceof Doc; + }); + if ($docs === []) { + return null; + } + $totalDocs = \count($docs); + foreach ($docs as $doc) { + $nodeToCheck = $totalDocs === 1 ? $node : clone $node; + if ($totalDocs > 1) { + $nodeToCheck->setDocComment($doc); + } + $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($nodeToCheck); + $names = \array_merge($names, $phpDocInfo->getAnnotationClassNames()); + $constFetchNodeNames = $phpDocInfo->getConstFetchNodeClassNames(); + $names = \array_merge($names, $constFetchNodeNames); + $genericTagClassNames = $phpDocInfo->getGenericTagClassNames(); + $names = \array_merge($names, $genericTagClassNames); + } }); return $names; }