@@ -128,7 +128,7 @@ protected function generateSecurityDefinitions()
128
128
129
129
protected function generatePath ()
130
130
{
131
- $ actionInstance = is_string ( $ this ->route -> action ()) ? $ this -> getActionClassInstance ($ this -> route -> action ()) : null ;
131
+ $ actionInstance = $ this ->getActionClassInstance () ;
132
132
$ docBlock = $ actionInstance ? ($ actionInstance ->getDocComment () ?: '' ) : '' ;
133
133
134
134
[$ isDeprecated , $ summary , $ description ] = $ this ->parseActionDocBlock ($ docBlock );
@@ -179,21 +179,31 @@ protected function addActionScopes()
179
179
}
180
180
}
181
181
182
- protected function getFormRules ()
182
+ protected function getFormRules () : array
183
183
{
184
- if (!is_string ($ this ->route ->action ())) {
185
- return false ;
184
+ $ action_instance = $ this ->getActionClassInstance ();
185
+
186
+ if (!$ action_instance ) {
187
+ return [];
186
188
}
187
189
188
- $ parameters = $ this -> getActionClassInstance ( $ this -> route -> action ()) ->getParameters ();
190
+ $ parameters = $ action_instance ->getParameters ();
189
191
190
192
foreach ($ parameters as $ parameter ) {
191
- $ class = ( string ) $ parameter ->getName ();
193
+ $ class = $ parameter ->getClass ();
192
194
193
- if (is_subclass_of ($ class , FormRequest::class)) {
194
- return (new $ class )->rules ();
195
+ if (!$ class ) {
196
+ continue ;
197
+ }
198
+
199
+ $ class_name = $ class ->getName ();
200
+
201
+ if (is_subclass_of ($ class_name , FormRequest::class)) {
202
+ return (new $ class_name )->rules ();
195
203
}
196
204
}
205
+
206
+ return [];
197
207
}
198
208
199
209
protected function getParameterGenerator ($ rules )
@@ -208,9 +218,13 @@ protected function getParameterGenerator($rules)
208
218
}
209
219
}
210
220
211
- private function getActionClassInstance (string $ action )
221
+ private function getActionClassInstance () : ? ReflectionMethod
212
222
{
213
- [$ class , $ method ] = Str::parseCallback ($ action );
223
+ [$ class , $ method ] = Str::parseCallback ($ this ->route ->action ());
224
+
225
+ if (!$ class || !$ method ) {
226
+ return null ;
227
+ }
214
228
215
229
return new ReflectionMethod ($ class , $ method );
216
230
}
0 commit comments