Skip to content
This repository was archived by the owner on Dec 6, 2022. It is now read-only.

Commit 7e0d58c

Browse files
author
Jefersson Nathan
committed
#44 — Remove duplicated call_user_func_array_code
1 parent 44a2594 commit 7e0d58c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/Route.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Fig\Http\Message\RequestMethodInterface;
2121
use Exception;
2222
use Interop\Container\ContainerInterface;
23+
use SebastianBergmann\GlobalState\RuntimeException;
2324

2425
class Route
2526
{
@@ -213,6 +214,12 @@ public function setParameters(array $parameters)
213214

214215
public function dispatch()
215216
{
217+
if (null === $this->getAction()) {
218+
throw new RuntimeException(
219+
sprintf('Could not find an action to controller "%s"', $this->controller)
220+
);
221+
}
222+
216223
if ($this->parametersByName) {
217224
$this->parameters = array($this->parameters);
218225
}
@@ -221,6 +228,11 @@ public function dispatch()
221228

222229
if ($this->container && $this->container->has($controller)) {
223230
$instance = $this->container->get($controller);
231+
} else {
232+
$instance = new $controller;
233+
}
234+
235+
if (method_exists($this, $this->getAction())){
224236
call_user_func_array(
225237
array($instance, $this->getAction()),
226238
$this->parameters
@@ -229,12 +241,7 @@ public function dispatch()
229241
return;
230242
}
231243

232-
if (!is_null($this->getAction())) {
233-
$instance = new $controller;
234-
call_user_func_array(array($instance, $this->getAction()), $this->parameters);
235-
} else {
236-
$instance = new $controller($this->parameters);
237-
}
244+
new $controller($this->parameters);
238245
}
239246

240247
public function getAction()

0 commit comments

Comments
 (0)