File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
rules-tests/Symfony73/Rector/Class_/ConstraintOptionsToNamedArgumentsRector/Fixture
rules/Symfony73/Rector/Class_ Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Symfony \Tests \Symfony73 \Rector \Class_ \ConstraintOptionsToNamedArgumentsRector \Fixture ;
4+
5+ use Symfony \Component \Form \AbstractType ;
6+ use Symfony \Component \Form \Extension \Core \Type \TextType ;
7+ use Symfony \Component \Form \FormBuilderInterface ;
8+ use Symfony \Component \Validator \Constraints \NotBlank ;
9+
10+ class SkipWithTranslateComment extends AbstractType
11+ {
12+ public function buildForm (FormBuilderInterface $ builder , array $ options ): void
13+ {
14+ $ builder
15+ ->add ('name ' , TextType::class, [
16+ 'constraints ' => [
17+ new NotBlank (['message ' =>
18+ // @Translate
19+ 'Name is required. '
20+ ]),
21+ ],
22+ ]);
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Symfony \Tests \Symfony73 \Rector \Class_ \ConstraintOptionsToNamedArgumentsRector \Fixture ;
4+
5+ use Symfony \Component \Form \AbstractType ;
6+ use Symfony \Component \Form \Extension \Core \Type \TextType ;
7+ use Symfony \Component \Form \FormBuilderInterface ;
8+ use Symfony \Component \Validator \Constraints \NotBlank ;
9+
10+ class SkipWithTranslateDocblock extends AbstractType
11+ {
12+ public function buildForm (FormBuilderInterface $ builder , array $ options ): void
13+ {
14+ $ builder
15+ ->add ('name ' , TextType::class, [
16+ 'constraints ' => [
17+ new NotBlank (['message ' => /** @Translate */ 'Name is required. ' ]),
18+ ],
19+ ]);
20+ }
21+ }
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ public function refactor(Node $node): ?Node
110110
111111 $ array = $ node ->args [0 ]->value ;
112112 $ namedArgs = [];
113+ $ oldTokens = $ this ->file ->getOldTokens ();
113114
114115 foreach ($ array ->items as $ item ) {
115116 if (! $ item instanceof ArrayItem) {
@@ -130,6 +131,22 @@ public function refactor(Node $node): ?Node
130131 continue ;
131132 }
132133
134+ $ lastTokenKey = $ item ->key ->getEndTokenPos ();
135+ $ startTokenValue = $ item ->value ->getStartTokenPos ();
136+
137+ while ($ lastTokenKey < $ startTokenValue ) {
138+ ++$ lastTokenKey ;
139+
140+ if (! isset ($ oldTokens [$ lastTokenKey ])) {
141+ break ;
142+ }
143+
144+ $ token = $ oldTokens [$ lastTokenKey ];
145+ if ($ token ->is ([T_DOC_COMMENT , T_COMMENT ])) {
146+ return null ;
147+ }
148+ }
149+
133150 $ arg = new Arg ($ item ->value );
134151 $ arg ->name = new Identifier ($ keyValue );
135152
You can’t perform that action at this time.
0 commit comments