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 |
||
22 | View Code Duplication | class SamplerAggregation extends AbstractAggregation |
|
|
|||
23 | { |
||
24 | use BucketingTrait; |
||
25 | |||
26 | /** |
||
27 | * Defines how many results will be received from each shard |
||
28 | * @param string $shardSize |
||
29 | */ |
||
30 | private $shardSize; |
||
31 | |||
32 | /** |
||
33 | * Inner aggregations container init. |
||
34 | * |
||
35 | * @param string $name |
||
36 | * @param string $field |
||
37 | * @param int $shardSize |
||
38 | */ |
||
39 | public function __construct($name, $field = null, $shardSize = null) |
||
46 | |||
47 | /** |
||
48 | * @return int |
||
49 | */ |
||
50 | public function getShardSize() |
||
54 | |||
55 | /** |
||
56 | * @param int $shardSize |
||
57 | * |
||
58 | * @return $this |
||
59 | */ |
||
60 | public function setShardSize($shardSize) |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | public function getType() |
||
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | public function getArray() |
||
89 | } |
||
90 |
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.