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 |
||
11 | View Code Duplication | class SumBucket extends AbstractAggregation |
|
|
|||
12 | { |
||
13 | /** |
||
14 | * @param string $name |
||
15 | * @param string|null $bucketsPath |
||
16 | */ |
||
17 | public function __construct($name, $bucketsPath = null) |
||
25 | |||
26 | /** |
||
27 | * Set the buckets_path for this aggregation. |
||
28 | * |
||
29 | * @param string $bucketsPath |
||
30 | * |
||
31 | * @return $this |
||
32 | */ |
||
33 | public function setBucketsPath($bucketsPath) |
||
37 | |||
38 | /** |
||
39 | * Set the gap policy for this aggregation. |
||
40 | * |
||
41 | * @param string $gapPolicy |
||
42 | * |
||
43 | * @return $this |
||
44 | */ |
||
45 | public function setGapPolicy($gapPolicy) |
||
49 | |||
50 | /** |
||
51 | * Set the format for this aggregation. |
||
52 | * |
||
53 | * @param string $format |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | public function setFormat($format) |
||
61 | |||
62 | /** |
||
63 | * @throws InvalidException If buckets path or script is not set |
||
64 | * |
||
65 | * @return array |
||
66 | */ |
||
67 | public function toArray() |
||
75 | } |
||
76 |
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.