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 |
||
23 | class CardinalityAggregation extends AbstractAggregation |
||
24 | { |
||
25 | use MetricTrait; |
||
26 | use ScriptAwareTrait; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | private $precisionThreshold; |
||
32 | |||
33 | /** |
||
34 | * @var bool |
||
35 | */ |
||
36 | private $rehash; |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | View Code Duplication | public function getArray() |
|
59 | |||
60 | /** |
||
61 | * @param int $precision |
||
62 | * |
||
63 | * @return $this |
||
64 | */ |
||
65 | public function setPrecisionThreshold($precision) |
||
71 | |||
72 | /** |
||
73 | * @return int |
||
74 | */ |
||
75 | public function getPrecisionThreshold() |
||
79 | |||
80 | /** |
||
81 | * @return bool |
||
82 | */ |
||
83 | public function isRehash() |
||
87 | |||
88 | /** |
||
89 | * @param bool $rehash |
||
90 | * |
||
91 | * @return $this |
||
92 | */ |
||
93 | public function setRehash($rehash) |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function getType() |
||
107 | |||
108 | /** |
||
109 | * Checks if required fields are set. |
||
110 | * |
||
111 | * @param array $fields |
||
112 | * |
||
113 | * @throws \LogicException |
||
114 | */ |
||
115 | private function checkRequiredFields($fields) |
||
121 | } |
||
122 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.