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 | 20 | 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 string $operator |
||
40 | */ |
||
41 | 15 | private function prepareFilterIndex(string $operator) |
|
47 | |||
48 | /** |
||
49 | * @param $expressions |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | 10 | private function mapExpressions($expressions): array |
|
62 | |||
63 | /** |
||
64 | * @return array |
||
65 | */ |
||
66 | 20 | public function getExpressionFilters(): array |
|
70 | |||
71 | /** |
||
72 | * @param array|Expression $expression |
||
73 | * |
||
74 | * @return $this |
||
75 | */ |
||
76 | 3 | View Code Duplication | public function or ($expression) |
87 | |||
88 | /** |
||
89 | * @param string $field |
||
90 | * @param string $value |
||
91 | * |
||
92 | * @return $this |
||
93 | */ |
||
94 | 2 | public function equal(string $field, $value) |
|
102 | |||
103 | /** |
||
104 | * @param string $operation |
||
105 | * @param mixed $value |
||
106 | * |
||
107 | * @return array |
||
108 | */ |
||
109 | 6 | private function operationExpression(string $operation, $value): array |
|
113 | |||
114 | /** |
||
115 | * @param string $field |
||
116 | * @param string $value |
||
117 | * |
||
118 | * @return $this |
||
119 | */ |
||
120 | 4 | public function notEqual(string $field, $value) |
|
128 | } |
||
129 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.