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 |
||
14 | View Code Duplication | class BucketAutoOutput extends AbstractOutput |
|
|
|||
15 | { |
||
16 | 3 | public function __construct(Builder $builder, Stage\BucketAuto $bucket) |
|
20 | |||
21 | /** |
||
22 | * An expression to group documents by. To specify a field path, prefix the |
||
23 | * field name with a dollar sign $ and enclose it in quotes. |
||
24 | */ |
||
25 | public function groupBy($expression) : Stage\BucketAuto |
||
30 | |||
31 | /** |
||
32 | * A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. |
||
33 | */ |
||
34 | public function buckets(int $buckets) : Stage\BucketAuto |
||
39 | |||
40 | /** |
||
41 | * A string that specifies the preferred number series to use to ensure that |
||
42 | * the calculated boundary edges end on preferred round numbers or their |
||
43 | * powers of 10. |
||
44 | */ |
||
45 | public function granularity(string $granularity) : Stage\BucketAuto |
||
50 | } |
||
51 |
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.