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 declare(strict_types = 1); |
||
| 8 | class Expression |
||
| 9 | { |
||
| 10 | /** @var array */ |
||
| 11 | private $queryPartial; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Expression constructor. |
||
| 15 | */ |
||
| 16 | public function __construct() |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param array|Expression $expression |
||
| 23 | * |
||
| 24 | * @return $this |
||
| 25 | */ |
||
| 26 | View Code Duplication | public function and($expression) |
|
| 37 | |||
| 38 | /** |
||
| 39 | * @param array|Expression $expression |
||
| 40 | * |
||
| 41 | * @return $this |
||
| 42 | */ |
||
| 43 | View Code Duplication | public function or($expression) |
|
| 54 | |||
| 55 | /** |
||
| 56 | * @return array |
||
| 57 | */ |
||
| 58 | public function getQueryPartial(): array |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param string $operator |
||
| 65 | */ |
||
| 66 | private function prepareOperator(string $operator) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param $expressions |
||
| 75 | * |
||
| 76 | * @return array |
||
| 77 | */ |
||
| 78 | private function mapExpressions($expressions): array |
||
| 87 | } |
||
| 88 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.