@@ -82,7 +82,7 @@ public function getController(Request $request)
82
82
if (!is_callable ($ callable )) {
83
83
$ message = sprintf ('The controller for URI "%s" is not callable. ' , $ request ->getPathInfo ());
84
84
85
- $ message .= $ this ->getControllerErrorMessage ($ callable );
85
+ $ message .= $ this ->getControllerError ($ callable );
86
86
87
87
throw new \InvalidArgumentException ($ message );
88
88
}
@@ -160,55 +160,52 @@ protected function createController($controller)
160
160
return array (new $ class (), $ method );
161
161
}
162
162
163
- private function getControllerErrorMessage ( $ callable )
163
+ private function getControllerError ( array $ callable )
164
164
{
165
- if (is_array ($ callable ) || (is_string ($ callable ) && false !== strpos ($ callable , ':: ' ))) {
166
- list ($ controller , $ method ) = is_array ($ callable ) ? $ callable : explode ($ callable , ':: ' );
165
+ list ($ controller , $ method ) = $ callable ;
167
166
168
- if (is_string ($ controller ) && !class_exists ($ controller )) {
169
- return sprintf ('Class "%s" does not exist. ' , $ controller );
170
- }
167
+ if (is_string ($ controller ) && !class_exists ($ controller )) {
168
+ return sprintf ('Class "%s" does not exist. ' , $ controller );
169
+ }
171
170
172
- $ reflection = new \ReflectionClass ($ controller );
171
+ $ reflection = new \ReflectionClass ($ controller );
173
172
174
- if (!method_exists ($ controller , $ method )) {
175
- $ collection = array_map (
176
- function (\ReflectionMethod $ method ) {
177
- return $ method ->getName ();
178
- },
179
- $ reflection ->getMethods (\ReflectionMethod::IS_PUBLIC )
180
- );
173
+ if (!method_exists ($ controller , $ method )) {
174
+ $ collection = array_map (
175
+ function (\ReflectionMethod $ method ) {
176
+ return $ method ->getName ();
177
+ },
178
+ $ reflection ->getMethods (\ReflectionMethod::IS_PUBLIC )
179
+ );
181
180
182
- $ alternatives = array ();
181
+ $ alternatives = array ();
183
182
184
- foreach ($ collection as $ item ) {
185
- $ lev = levenshtein ($ method , $ item );
183
+ foreach ($ collection as $ item ) {
184
+ $ lev = levenshtein ($ method , $ item );
186
185
187
- if ($ lev <= strlen ($ method ) / 3 || false !== strpos ($ item , $ method )) {
188
- $ alternatives [$ item ] = isset ($ alternatives [$ item ]) ? $ alternatives [$ item ] - $ lev : $ lev ;
189
- }
186
+ if ($ lev <= strlen ($ method ) / 3 || false !== strpos ($ item , $ method )) {
187
+ $ alternatives [$ item ] = isset ($ alternatives [$ item ]) ? $ alternatives [$ item ] - $ lev : $ lev ;
190
188
}
189
+ }
191
190
192
- asort ($ alternatives );
191
+ asort ($ alternatives );
193
192
194
- $ message = sprintf ('Expected method "%s" on class "%s" ' , $ method , $ reflection ->getName ());
193
+ $ message = sprintf ('Expected method "%s" on class "%s" ' , $ method , $ reflection ->getName ());
195
194
196
- if (count ($ alternatives ) > 0 ) {
197
- $ message .= sprintf (', did you mean "%s"? ' , implode ('", " ' , array_keys ($ alternatives )));
198
- } else {
199
- $ message .= sprintf ('. Available methods: "%s" ' , implode ('", " ' , $ collection ));
200
- }
201
-
202
- return $ message ;
195
+ if (count ($ alternatives ) > 0 ) {
196
+ $ message .= sprintf (', did you mean "%s"? ' , implode ('", " ' , array_keys ($ alternatives )));
197
+ } else {
198
+ $ message .= sprintf ('. Available methods: "%s" ' , implode ('", " ' , $ collection ));
203
199
}
204
200
205
- return sprintf (
206
- 'Method "%s" on class "%s" should be public and non-abstract ' ,
207
- $ method ,
208
<
83F5
code> - $ reflection ->getName ()
209
- );
210
- } elseif (is_string ($ callable ) && !function_exists ($ callable )) {
211
- return sprintf ('Function "%s" does not exist. ' , $ callable );
201
+ return $ message ;
212
202
}
203
+
204
+ return sprintf (
205
+ 'Method "%s" on class "%s" should be public and non-abstract ' ,
206
+ $ method ,
207
+ $ reflection ->getName ()
208
+ );
209
+
213
210
}
214
211
}
0 commit comments