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 |
||
| 20 | class ClosureAutoBind implements Dispatcher |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Not found handler will be called if nothing has been found. |
||
| 24 | * |
||
| 25 | * @var \Closure |
||
| 26 | */ |
||
| 27 | private $notFoundHandler; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Dispatch found route with given parameters |
||
| 31 | * |
||
| 32 | * @param \Kambo\Router\Route\Route\Parsed $route Instance of found and parsed route. |
||
| 33 | * @param array $parameters Additional parameters which will be passed into |
||
| 34 | * the dispatcher. |
||
| 35 | * |
||
| 36 | * @return mixed |
||
| 37 | */ |
||
| 38 | public function dispatchRoute(Parsed $route, array $parameters) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Called if any of route did not match the request. |
||
| 57 | * Call the defined handler or simply do nothing if the handler is not |
||
| 58 | * specified. |
||
| 59 | * |
||
| 60 | * @return mixed|null |
||
| 61 | */ |
||
| 62 | public function dispatchNotFound() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Sets not found handler |
||
| 73 | * |
||
| 74 | * @param string $handler handler that will be excuted if nothing has been |
||
| 75 | * found |
||
| 76 | * |
||
| 77 | * @return self for fluent interface |
||
| 78 | * |
||
| 79 | * @throws InvalidArgumentException if the provided value is not closure |
||
| 80 | */ |
||
| 81 | public function setNotFoundHandler($handler) |
||
| 93 | |||
| 94 | // ------------ PRIVATE METHODS |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Check if variable is closure |
||
| 98 | * |
||
| 99 | * @param mixed $type variable to check |
||
| 100 | * |
||
| 101 | * @return boolean return true if is |
||
| 102 | */ |
||
| 103 | private function isClosure($type) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Get arguments for closure function in proper order |
||
| 110 | * from provided parameters |
||
| 111 | * |
||
| 112 | * @param mixed $paramMap parameter map for getting proper order |
||
| 113 | * @param mixed $matches parameters from request |
||
| 114 | * @param mixed $parameters expected parameters from route |
||
| 115 | * |
||
| 116 | * @return array Parameters in right order, if there are not any |
||
| 117 | * parametrs an empty array is returned. |
||
| 118 | */ |
||
| 119 | private function getFunctionArguments($paramMap, $matches, $parameters) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Get name of parameters for provided closure |
||
| 138 | * |
||
| 139 | * @param \Closure $closure |
||
| 140 | * |
||
| 141 | * @return array |
||
| 142 | */ |
||
| 143 | private function getFunctionArgumentsNames($closure) |
||
| 153 | } |
||
| 154 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..