File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
tests/Rector/MethodCall/ValidationRuleArrayStringValueToArrayRector/Fixture Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ public function refactor(Node $node): MethodCall|StaticCall|ClassLike|null
63
63
return $ this ->refactorClassMethod ($ node );
64
64
}
65
65
66
+ if ($ node instanceof MethodCall && $ this ->isName ($ node ->name , 'validate ' )) {
67
+ return $ this ->refactorValidateCall ($ node );
68
+ }
69
+
66
70
return $ this ->refactorCall ($ node );
67
71
}
68
72
@@ -184,6 +188,30 @@ private function refactorCall(StaticCall|MethodCall $node): StaticCall|MethodCal
184
188
return $ this ->processValidationRules ($ rulesArgument ) ? $ node : null ;
185
189
}
186
190
191
+ private function refactorValidateCall (MethodCall $ methodCall ): ?MethodCall
192
+ {
193
+ if (! $ this ->isObjectType ($ methodCall ->var , new ObjectType ('Illuminate\Http\Request ' ))) {
194
+ return null ;
195
+ }
196
+
197
+ if ($ methodCall ->args === []) {
198
+ return null ;
199
+ }
200
+
201
+ if (! $ methodCall ->args [0 ] instanceof Arg) {
202
+ return null ;
203
+ }
204
+
205
+ // The first argument should be the rules array
206
+ $ rulesArgument = $ methodCall ->args [0 ]->value ;
207
+
208
+ if (! $ rulesArgument instanceof Array_) {
209
+ return null ;
210
+ }
211
+
212
+ return $ this ->processValidationRules ($ rulesArgument ) ? $ methodCall : null ;
213
+ }
214
+
187
215
private function refactorClassMethod (ClassLike $ classLike ): ?ClassLike
188
216
{
189
217
if (! $ this ->isObjectType ($ classLike , new ObjectType ('Illuminate\Foundation\Http\FormRequest ' ))) {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace RectorLaravel \Tests \Rector \MethodCall \ValidationRuleArrayStringValueToArrayRector \Fixture ;
4
+
5
+ class AppliesToHttpRequests
6
+ {
7
+ public function store (\Illuminate \Http \Request $ request )
8
+ {
9
+ $ request ->validate ([
10
+ 'name ' => 'required|string ' ,
11
+ ]);
12
+ }
13
+ }
14
+
15
+ ?>
16
+ -----
17
+ <?php
18
+
19
+ namespace RectorLaravel \Tests \Rector \MethodCall \ValidationRuleArrayStringValueToArrayRector \Fixture ;
20
+
21
+ class AppliesToHttpRequests
22
+ {
23
+ public function store (\Illuminate \Http \Request $ request )
24
+ {
25
+ $ request ->validate ([
26
+ 'name ' => ['required ' , 'string ' ],
27
+ ]);
28
+ }
29
+ }
30
+
31
+ ?>
You can’t perform that action at this time.
0 commit comments