Skip to content

Commit cc00d60

Browse files
committed
Updated Rector to commit 142f1c81c7a9d26fd5119526186aba14f4cf6382
rectorphp/rector-src@142f1c8 [DeadCode] Handle only remove 1 @var on multi vars on RemoveUselessVarTagRector (#7884)
1 parent ca9ebb8 commit cc00d60

4 files changed

Lines changed: 23 additions & 8 deletions

File tree

rules/DeadCode/PhpDoc/TagRemover/VarTagRemover.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ public function __construct(DoctrineTypeAnalyzer $doctrineTypeAnalyzer, PhpDocIn
5454
$this->typeComparator = $typeComparator;
5555
}
5656
/**
57-
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassConst|\PhpParser\Node\Stmt\Expression $property
57+
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassConst|\PhpParser\Node\Stmt\Expression $node
5858
*/
59-
public function removeVarTagIfUseless(PhpDocInfo $phpDocInfo, $property): bool
59+
public function removeVarTagIfUseless(PhpDocInfo $phpDocInfo, $node): bool
6060
{
6161
$varTagValueNode = $phpDocInfo->getVarTagValueNode();
6262
if (!$varTagValueNode instanceof VarTagValueNode) {
6363
return \false;
6464
}
65-
$isVarTagValueDead = $this->deadVarTagValueNodeAnalyzer->isDead($varTagValueNode, $property);
65+
$isVarTagValueDead = $this->deadVarTagValueNodeAnalyzer->isDead($varTagValueNode, $node);
6666
if (!$isVarTagValueDead) {
6767
return \false;
6868
}
6969
if ($this->phpDocTypeChanger->isAllowed($varTagValueNode->type)) {
7070
return \false;
7171
}
72-
$phpDocInfo->removeByType(VarTagValueNode::class);
73-
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property);
72+
$phpDocInfo->removeByType(VarTagValueNode::class, $varTagValueNode->variableName);
73+
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
7474
return \true;
7575
}
7676
/**

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '2.3.6';
22+
public const PACKAGE_VERSION = '142f1c81c7a9d26fd5119526186aba14f4cf6382';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2026-02-05 16:20:29';
27+
public const RELEASE_DATE = '2026-02-06 17:31:57';
2828
/**
2929
* @var int
3030
*/

src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ public function findOneByAnnotationClass(string $desiredClass): ?DoctrineAnnotat
232232
public function removeByType(string $typeToRemove, ?string $name = null): bool
233233
{
234234
$hasChanged = \false;
235+
if ($name === '') {
236+
$name = null;
237+
}
235238
$phpDocNodeTraverser = new PhpDocNodeTraverser();
236239
$phpDocNodeTraverser->traverseWithCallable($this->phpDocNode, '', static function (Node $node) use ($typeToRemove, &$hasChanged, $name): ?int {
237240
if ($node instanceof PhpDocTagNode && $node->value instanceof $typeToRemove) {

src/Comments/NodeDocBlock/DocBlockUpdater.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,19 @@ public function updateRefactoredNodeWithPhpDocInfo(Node $node): void
3939
}
4040
private function setCommentsAttribute(Node $node): void
4141
{
42-
$comments = array_filter($node->getComments(), static fn(Comment $comment): bool => !$comment instanceof Doc);
42+
$docComment = $node->getDocComment();
43+
$docCommentText = $docComment instanceof Doc ? $docComment->getText() : null;
44+
$comments = array_filter($node->getComments(), static function (Comment $comment) use ($docCommentText): bool {
45+
if (!$comment instanceof Doc) {
46+
return \true;
47+
}
48+
// remove only the docblock that belongs to the node itself;
49+
// keep other preceding docblocks (possible with multiple @var docblocks before a statement)
50+
if ($docCommentText !== null && $comment->getText() === $docCommentText) {
51+
return \false;
52+
}
53+
return \true;
54+
});
4355
$node->setAttribute(AttributeKey::COMMENTS, array_values($comments));
4456
}
4557
private function clearEmptyDoc(Node $node): void

0 commit comments

Comments
 (0)