44
55namespace Rector \DowngradePhp80 \Rector \Class_ ;
66
7- use PhpParser \Comment ;
87use PhpParser \Node ;
98use PhpParser \Node \Attribute ;
109use PhpParser \Node \Param ;
2019use Rector \Contract \Rector \ConfigurableRectorInterface ;
2120use Rector \DowngradePhp80 \ValueObject \DowngradeAttributeToAnnotation ;
2221use Rector \NodeFactory \DoctrineAnnotationFactory ;
23- use Rector \NodeTypeResolver \Node \AttributeKey ;
24- use Rector \PhpParser \Printer \BetterStandardPrinter ;
2522use Rector \Rector \AbstractRector ;
2623use Symplify \RuleDocGenerator \ValueObject \CodeSample \ConfiguredCodeSample ;
2724use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
@@ -49,8 +46,7 @@ final class DowngradeAttributeToAnnotationRector extends AbstractRector implemen
4946 public function __construct (
5047 private readonly DoctrineAnnotationFactory $ doctrineAnnotationFactory ,
5148 private readonly DocBlockUpdater $ docBlockUpdater ,
52- private readonly PhpDocInfoFactory $ phpDocInfoFactory ,
53- private readonly BetterStandardPrinter $ betterStandardPrinter
49+ private readonly PhpDocInfoFactory $ phpDocInfoFactory
5450 ) {
5551 }
5652
@@ -109,7 +105,6 @@ public function refactor(Node $node): ?Node
109105 $ this ->isDowngraded = false ;
110106
111107 $ phpDocInfo = $ this ->phpDocInfoFactory ->createFromNodeOrEmpty ($ node );
112- $ attributesAsComments = [];
113108 $ oldTokens = $ this ->file ->getOldTokens ();
114109
115110 foreach ($ node ->attrGroups as $ attrGroup ) {
@@ -119,10 +114,9 @@ public function refactor(Node $node): ?Node
119114 (string ) $ oldTokens [$ attrGroup ->getEndTokenPos () + 1 ],
120115 "\n"
121116 )) {
122- $ print = $ this ->betterStandardPrinter ->print ($ attrGroup );
123- $ attributesAsComments [] = new Comment ($ print );
124-
125- unset($ attrGroup ->attrs [$ key ]);
117+ // add new line
118+ $ oldTokens [$ attrGroup ->getEndTokenPos () + 1 ]->text = "\n" . $ oldTokens [$ attrGroup ->getEndTokenPos () + 1 ]->text ;
119+ $ this ->isDowngraded = true ;
126120 }
127121
128122 continue ;
@@ -161,12 +155,6 @@ public function refactor(Node $node): ?Node
161155 // cleanup empty attr groups
162156 $ this ->cleanupEmptyAttrGroups ($ node );
163157
164- if ($ attributesAsComments !== []) {
165- $ this ->isDowngraded = true ;
166- $ currentComments = $ node ->getAttribute (AttributeKey::COMMENTS ) ?? [];
167- $ node ->setAttribute (AttributeKey::COMMENTS , array_merge ($ currentComments , $ attributesAsComments ));
168- }
169-
170158 if (! $ this ->isDowngraded ) {
171159 return null ;
172160 }
0 commit comments