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 |
||
| 17 | class Builder |
||
| 18 | { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $root; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Builder constructor. |
||
| 27 | * |
||
| 28 | * @param string $root |
||
| 29 | */ |
||
| 30 | 8 | public function __construct(string $root) |
|
| 34 | |||
| 35 | /** |
||
| 36 | * @return Config |
||
| 37 | */ |
||
| 38 | public function config(): Config |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @return Router |
||
| 47 | */ |
||
| 48 | public function router(): Router |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return ServerRequestInterface |
||
| 57 | */ |
||
| 58 | 1 | private function _request(): ServerRequestInterface |
|
| 80 | |||
| 81 | /** |
||
| 82 | * @return ServerRequestInterface |
||
| 83 | */ |
||
| 84 | public function request(): ServerRequestInterface |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @return Session |
||
| 113 | */ |
||
| 114 | View Code Duplication | public function session(): Session |
|
| 125 | |||
| 126 | /** |
||
| 127 | * @return Cookies |
||
| 128 | */ |
||
| 129 | View Code Duplication | public function cookies(): Cookies |
|
| 140 | |||
| 141 | /** |
||
| 142 | * @return Factory |
||
| 143 | */ |
||
| 144 | public function factory(): Factory |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @return Flow |
||
| 153 | */ |
||
| 154 | public function flow(): Flow |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @return Password |
||
| 163 | */ |
||
| 164 | View Code Duplication | public function password(): Password |
|
| 176 | |||
| 177 | } |
||
| 178 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.