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 $filters; |
||
12 | |||
13 | /** |
||
14 | * Expression constructor. |
||
15 | */ |
||
16 | 14 | 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 | * @param string $field |
||
57 | * @param Expression[]|array $expressions |
||
58 | */ |
||
59 | 2 | public function notEqual(string $field, ...$expressions) |
|
68 | |||
69 | /** |
||
70 | * @return array |
||
71 | */ |
||
72 | 14 | public function getExpressionFilters(): array |
|
76 | |||
77 | /** |
||
78 | * @param string $operator |
||
79 | */ |
||
80 | 9 | private function prepareFilterIndex(string $operator) |
|
86 | |||
87 | /** |
||
88 | * @param $expressions |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | 7 | private function mapExpressions($expressions): array |
|
101 | |||
102 | /** |
||
103 | * @param string $operation |
||
104 | * @param array $expressions |
||
105 | * |
||
106 | * @return array |
||
107 | */ |
||
108 | 2 | private function operationExpressions(string $operation, array $expressions): array |
|
119 | } |
||
120 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.