1 | <?php |
||
9 | class CDispatcherBasic implements \Anax\DI\IInjectionAware |
||
10 | { |
||
11 | use \Anax\DI\TInjectionAware; |
||
12 | |||
13 | |||
14 | |||
15 | /** |
||
16 | * Properties |
||
17 | * |
||
18 | */ |
||
19 | private $controllerName; // Name of controller |
||
20 | private $controller; // Actual controller |
||
21 | private $action; // Name of action |
||
22 | private $params; // Params |
||
23 | |||
24 | |||
25 | |||
26 | /** |
||
27 | * Prepare the name. |
||
28 | * |
||
29 | * @param string $name to prepare. |
||
30 | * |
||
31 | * @return string as the prepared name. |
||
32 | */ |
||
33 | 2 | public function prepareName($name) |
|
34 | { |
||
35 | 2 | $name = empty($name) ? 'index' : $name; |
|
36 | 2 | $name = strtolower($name); |
|
37 | 2 | $name = str_replace(['-', '_'], ' ', $name); |
|
38 | 2 | $name = ucwords($name); |
|
39 | 2 | $name = str_replace(' ', '', $name); |
|
40 | |||
41 | 2 | return $name; |
|
42 | } |
||
43 | |||
44 | |||
45 | |||
46 | /** |
||
47 | * Set the name of the controller. |
||
48 | * |
||
49 | * @param string $name of the controller, defaults to 'index'. |
||
50 | * |
||
51 | * @return void |
||
52 | */ |
||
53 | 2 | public function setControllerName($name = 'index') |
|
54 | { |
||
55 | 2 | $name = $this->prepareName($name) . 'Controller'; |
|
56 | |||
57 | 2 | $this->controllerName = $name; |
|
58 | |||
59 | 2 | $this->controller = $this->di->has($name) |
|
60 | 2 | ? $this->di->get($name) |
|
61 | 2 | : null; |
|
62 | 2 | } |
|
63 | |||
64 | |||
65 | |||
66 | /** |
||
67 | * Check if a controller exists with this name. |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | 2 | public function isValidController() |
|
75 | |||
76 | |||
77 | |||
78 | /** |
||
79 | * Set the name of the action. |
||
80 | * |
||
81 | * @param string $name of the action, defaults to 'index'. |
||
82 | * |
||
83 | * @return void |
||
84 | */ |
||
85 | 2 | public function setActionName($name = 'index') |
|
89 | |||
90 | |||
91 | |||
92 | /** |
||
93 | * Set the params. |
||
94 | * |
||
95 | * @param array $params all parameters, defaults to empty. |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | 1 | public function setParams($params = []) |
|
100 | { |
||
101 | 1 | $this->params = $params; |
|
102 | 1 | } |
|
103 | |||
104 | |||
105 | |||
106 | /** |
||
107 | * Dispatch to a controller, action with parameters. |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function isCallable() |
||
126 | |||
127 | |||
128 | /** |
||
129 | * Inspect if callable and throw exception if parts is not callable. |
||
130 | * |
||
131 | * @return void |
||
132 | * @throws \Exception |
||
133 | */ |
||
134 | 2 | public function isCallableOrException() |
|
180 | |||
181 | |||
182 | |||
183 | /** |
||
184 | * Dispatch to a controller, action with parameters. |
||
185 | * |
||
186 | * @return mixed result from dispatched controller action. |
||
187 | */ |
||
188 | 2 | public function dispatch() |
|
199 | |||
200 | |||
201 | /** |
||
202 | * Forward to a controller, action with parameters. |
||
203 | * |
||
204 | * @param array $forward with details for controller, action, parameters. |
||
205 | * |
||
206 | * @return mixed result from dispatched controller action. |
||
207 | */ |
||
208 | public function forward($forward = []) |
||
229 | |||
230 | |||
231 | /** |
||
232 | * Checks if the number of parameters given are valid. |
||
233 | * Make sure you have set and validated the controller and action before executing this function. |
||
234 | * |
||
235 | * @return bool if valid. |
||
236 | */ |
||
237 | 1 | public function isParamsValid() |
|
249 | } |
||
250 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.