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 |
||
| 30 | class PaginationBuilder extends AbstractPlugin |
||
| 31 | { |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The internal configuration stack. |
||
| 35 | * |
||
| 36 | * @var array |
||
| 37 | */ |
||
| 38 | protected $stack = []; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * The generated result array. |
||
| 42 | * |
||
| 43 | * @var array |
||
| 44 | */ |
||
| 45 | protected $result = []; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Internal parameters. |
||
| 49 | * |
||
| 50 | * @var Parameters |
||
| 51 | */ |
||
| 52 | protected $parameters; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Entry point. |
||
| 56 | * |
||
| 57 | * if $stack is provided, the internal stack is set to exact that value, so |
||
| 58 | * please be sure what you're doing. |
||
| 59 | * |
||
| 60 | * If you pass a boolean TRUE as $stack, the internal stack is reset. |
||
| 61 | * |
||
| 62 | * @param null|array|bool $stack |
||
| 63 | * @param bool $returnResult Should the result be immediately be returned instead of |
||
| 64 | * self. Only affective when $stack is an array. |
||
| 65 | * |
||
| 66 | * @return self|array |
||
| 67 | * @throws \InvalidArgumentException |
||
| 68 | */ |
||
| 69 | public function __invoke($stack = null, $returnResult = true) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Add arguments for the call to the CreatePaginator plugin. |
||
| 98 | * |
||
| 99 | * @see \Core\Controller\Plugin\CreatePaginator::__invoke() |
||
| 100 | * |
||
| 101 | * @param string $paginatorName |
||
| 102 | * @param array $defaultParams |
||
| 103 | * @param string $as The name of the key in the result array. |
||
| 104 | * |
||
| 105 | * @return self |
||
| 106 | */ |
||
| 107 | public function paginator($paginatorName, $defaultParams = [], $as = 'paginator') |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Add arguments for the call to the SearchForm plugin. |
||
| 120 | * |
||
| 121 | * @see \Core\Controller\Plugin\SearchForm::get() |
||
| 122 | * |
||
| 123 | * @param $elementsFieldset |
||
| 124 | * @param null $buttonsFieldset |
||
|
|
|||
| 125 | * @param string $as The name of the key in the result array. |
||
| 126 | * |
||
| 127 | * @return self |
||
| 128 | */ |
||
| 129 | public function form($form, $options = null, $as = 'searchform') |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Add arguments for the call to the PaginatorParams plugin. |
||
| 142 | * |
||
| 143 | * @see \Core\Controller\Plugin\PaginationParams::getParams() |
||
| 144 | * |
||
| 145 | * @param $namespace |
||
| 146 | * @param array $defaults |
||
| 147 | * |
||
| 148 | * @return self |
||
| 149 | */ |
||
| 150 | public function params($namespace, $defaults = [ 'page' => 1 ]) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Calls the stacked plugins in the right order and returns the result array. |
||
| 158 | * |
||
| 159 | * The returned array can directly be returned from the controller or be used to populate a |
||
| 160 | * view model. |
||
| 161 | * |
||
| 162 | * The search form plugin is only called (and thus the form only present in the result array) |
||
| 163 | * if the request is NOT an ajax request. (as the form is never rerendered on ajax requests) |
||
| 164 | * |
||
| 165 | * @param null|string $paginatorAlias Name of the paginator in the result array |
||
| 166 | * @param null|string $formAlias Name of the search form in the result array |
||
| 167 | * |
||
| 168 | * @return array |
||
| 169 | */ |
||
| 170 | public function getResult($paginatorAlias = null, $formAlias = null) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Calls an invokable controller plugin. |
||
| 210 | * |
||
| 211 | * @param string $name |
||
| 212 | * @param array $args |
||
| 213 | * |
||
| 214 | * @return mixed The return value of the called plugin. |
||
| 215 | */ |
||
| 216 | protected function callPlugin($name, $args) |
||
| 232 | |||
| 233 | protected function setParameters($query) |
||
| 253 | } |
||
| 254 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.