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

Commit fea9a8d

Browse files
author
Jefersson Nathan
committed
#44 — Remove duplicated call_user_func_array_code
1 parent ae13216 commit fea9a8d

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
@@ -18,6 +18,7 @@
1818
namespace PHPRouter;
1919

2020
use Interop\Container\ContainerInterface;
21+
use SebastianBergmann\GlobalState\RuntimeException;
2122

2223
class Route
2324
{
@@ -186,6 +187,12 @@ public function setParameters(array $parameters)
186187

187188
public function dispatch()
188189
{
190+
if (null === $this->getAction()) {
191+
throw new RuntimeException(
192+
sprintf('Could not find an action to controller "%s"', $this->controller)
193+
);
194+
}
195+
189196
if ($this->parametersByName) {
190197
$this->parameters = array($this->parameters);
191198
}
@@ -194,6 +201,11 @@ public function dispatch()
194201

195202
if ($this->container && $this->container->has($controller)) {
196203
$instance = $this->container->get($controller);
204+
} else {
205+
$instance = new $controller;
206+
}
207+
208+
if (method_exists($this, $this->getAction())){
197209
call_user_func_array(
198210
array($instance, $this->getAction()),
199211
$this->parameters
@@ -202,12 +214,7 @@ public function dispatch()
202214
return;
203215
}
204216

205-
if (!is_null($this->getAction())) {
206-
$instance = new $controller;
207-
call_user_func_array(array($instance, $this->getAction()), $this->parameters);
208-
} else {
209-
$instance = new $controller($this->parameters);
210-
}
217+
new $controller($this->parameters);
211218
}
212219

213220
public function getAction()

0 commit comments

Comments
 (0)