8000 Simplified controller error message check · symfony/symfony@9323a00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9323a00

Browse files
committed
Simplified controller error message check
1 parent 4ca0464 commit 9323a00

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function getController(Request $request)
8282
if (!is_callable($callable)) {
8383
$message = sprintf('The controller for URI "%s" is not callable. ', $request->getPathInfo());
8484

85-
$message .= $this->getControllerErrorMessage($callable);
85+
$message .= $this->getControllerError($callable);
8686

8787
throw new \InvalidArgumentException($message);
8888
}
@@ -160,55 +160,52 @@ protected function createController($controller)
160160
return array(new $class(), $method);
161161
}
162162

163-
private function getControllerErrorMessage($callable)
163+
private function getControllerError(array $callable)
164164
{
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;
167166

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+
}
171170

172-
$reflection = new \ReflectionClass($controller);
171+
$reflection = new \ReflectionClass($controller);
173172

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+
);
181180

182-
$alternatives = array();
181+
$alternatives = array();
183182

184-
foreach ($collection as $item) {
185-
$lev = levenshtein($method, $item);
183+
foreach ($collection as $item) {
184+
$lev = levenshtein($method, $item);
186185

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;
190188
}
189+
}
191190

192-
asort($alternatives);
191+
asort($alternatives);
193192

194-
$message = sprintf('Expected method "%s" on class "%s"', $method, $reflection->getName());
193+
$message = sprintf('Expected method "%s" on class "%s"', $method, $reflection->getName());
195194

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));
203199
}
204200

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;
212202
}
203+
204+
return sprintf(
205+
'Method "%s" on class "%s" should be public and non-abstract',
206+
$method,
207+
$reflection->getName()
208+
);
209+
213210
}
214211
}

0 commit comments

Comments
 (0)
0