Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
18 | class ClassAutoBind implements Dispatcher |
||
19 | { |
||
20 | /** |
||
21 | * Not found handler which will be called if nothing has been found. |
||
22 | * |
||
23 | * @var mixed |
||
24 | */ |
||
25 | private $notFoundHandler; |
||
26 | |||
27 | /** |
||
28 | * Base namespace for all dispatched classes. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $baseNamespace = null; |
||
33 | |||
34 | /** |
||
35 | * Name of class that will be used for constructing a namespace for proper |
||
36 | * class resolve. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | private $controllerName = 'Controllers'; |
||
41 | |||
42 | /** |
||
43 | * Name of module that will be used for constructing a namespace for proper |
||
44 | * class resolve. |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | private $moduleName = 'Modules'; |
||
49 | |||
50 | /** |
||
51 | * Prefix for action method. |
||
52 | * Target method is allways called with this prefix. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | private $actionName = 'action'; |
||
57 | |||
58 | /** |
||
59 | * Dispatch found route with given parameters |
||
60 | * |
||
61 | * @param \Kambo\Router\Route\Route\Parsed $route Instance of found and parsed route. |
||
62 | * @param array $parameters Additional parameters which will be passed into |
||
63 | * the dispatcher. |
||
64 | * |
||
65 | * @return mixed |
||
66 | */ |
||
67 | public function dispatchRoute(Parsed $route, array $parameters) |
||
106 | |||
107 | /** |
||
108 | * Called if any of route did not match the request. |
||
109 | * |
||
110 | * @return mixed |
||
111 | */ |
||
112 | public function dispatchNotFound() |
||
137 | |||
138 | /** |
||
139 | * Set base namespace to allow proper resolve of class name |
||
140 | * |
||
141 | * @param string $baseNamespace base namespace |
||
142 | * |
||
143 | * @return self for fluent interface |
||
144 | */ |
||
145 | public function setBaseNamespace($baseNamespace) |
||
151 | |||
152 | /** |
||
153 | * Sets not found handler |
||
154 | * |
||
155 | * @param string $handler handler that will be excuted if nothing has been |
||
156 | * found |
||
157 | * |
||
158 | * @return self for fluent interface |
||
159 | */ |
||
160 | public function setNotFoundHandler($handler) |
||
166 | |||
167 | // ------------ PRIVATE METHODS |
||
168 | |||
169 | /** |
||
170 | * Resolve target name of class (controller) and method (action) |
||
171 | * |
||
172 | * @param mixed $matches found matched variables |
||
173 | * @param mixed $parameters route parameters |
||
174 | * @param mixed $handler handler that should be executed |
||
175 | * |
||
176 | * @return mixed |
||
177 | */ |
||
178 | private function resolveControlerAction($matches, $parameters, $handler) |
||
203 | |||
204 | /** |
||
205 | * Transform provided handler with variables and parameters |
||
206 | * |
||
207 | * @param mixed $matches found matched variables |
||
208 | * @param mixed $parameters route parameters |
||
209 | * @param mixed $handler handler that should be executed |
||
210 | * |
||
211 | * @return mixed |
||
212 | */ |
||
213 | private function transformHandler($matches, $parameters, $handler) |
||
230 | |||
231 | /** |
||
232 | * Resolve proper namespace according parameters, handler and matches |
||
233 | * |
||
234 | * @param mixed $parameters route parameters |
||
235 | * @param mixed $handler handler that should be executed |
||
236 | * @param mixed $matches found matched variables |
||
237 | |||
238 | * @return mixed |
||
239 | */ |
||
240 | private function resolveNamespace($parameters, $handler, $matches) |
||
269 | |||
270 | /** |
||
271 | * Check if the variable is placeholder |
||
272 | * |
||
273 | * @param string $value found route |
||
274 | * |
||
275 | * @return boolean true if value should be transfered |
||
276 | */ |
||
277 | private function isPlaceholder($value) |
||
285 | |||
286 | /** |
||
287 | * Get function arguments for controler |
||
288 | * |
||
289 | * @param mixed $paramMap parameter map |
||
290 | * @param mixed $matches found matched variables |
||
291 | * @param mixed $parameters route parameters |
||
292 | * @param mixed $handlers handler that should be executed |
||
293 | |||
294 | * @return mixed |
||
295 | */ |
||
296 | private function getFunctionArgumentsControlers( |
||
331 | |||
332 | /** |
||
333 | * Get names of parameters for provided class and method |
||
334 | * |
||
335 | * @param class $class name of class |
||
336 | * @param string $methodName name of method |
||
337 | * |
||
338 | * @return array |
||
339 | */ |
||
340 | private function getMethodParameters($class, $methodName) |
||
350 | } |
||
351 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: