Skip to content

Commit 8f80d64

Browse files
committed
reprint with skipped attribute
1 parent d64ca76 commit 8f80d64

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

rules-tests/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector/Fixture/reprint_same_line.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradeAttributeToAnnotati
1717
use AllowDynamicProperties;
1818

1919
#[AllowDynamicProperties]
20-
class User
20+
class ReprintSameLine
2121
{
2222
}
2323

rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Rector\Contract\Rector\ConfigurableRectorInterface;
2020
use Rector\DowngradePhp80\ValueObject\DowngradeAttributeToAnnotation;
2121
use Rector\NodeFactory\DoctrineAnnotationFactory;
22+
use Rector\NodeTypeResolver\Node\AttributeKey;
2223
use Rector\Rector\AbstractRector;
2324
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
2425
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -105,9 +106,11 @@ public function refactor(Node $node): ?Node
105106
$this->isDowngraded = false;
106107

107108
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
109+
$requireReprint = false;
108110
foreach ($node->attrGroups as $attrGroup) {
109111
foreach ($attrGroup->attrs as $key => $attribute) {
110112
if ($this->shouldSkipAttribute($attribute)) {
113+
$requireReprint = true;
111114
continue;
112115
}
113116

@@ -145,6 +148,11 @@ public function refactor(Node $node): ?Node
145148
$this->cleanupEmptyAttrGroups($node);
146149

147150
if (! $this->isDowngraded) {
151+
if ($requireReprint) {
152+
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
153+
return $node;
154+
}
155+
148156
return null;
149157
}
150158

0 commit comments

Comments
 (0)