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 | class TermsTest extends BaseAggregationTest |
||
15 | { |
||
16 | /** |
||
17 | * @group unit |
||
18 | */ |
||
19 | public function testIncludePattern(): void |
||
26 | |||
27 | /** |
||
28 | * @group unit |
||
29 | */ |
||
30 | View Code Duplication | public function testIncludeExactMatch(): void |
|
|
|||
31 | { |
||
32 | $agg = new Terms('terms'); |
||
33 | $agg->setIncludeAsExactMatch(['first', 'second']); |
||
34 | |||
35 | $this->assertSame(['first', 'second'], $agg->getParam('include')); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @group unit |
||
40 | */ |
||
41 | View Code Duplication | public function testIncludeWithPartitions(): void |
|
51 | |||
52 | /** |
||
53 | * @group unit |
||
54 | */ |
||
55 | public function testExcludePattern(): void |
||
62 | |||
63 | /** |
||
64 | * @group unit |
||
65 | */ |
||
66 | View Code Duplication | public function testExcludeExactMatch(): void |
|
73 | |||
74 | /** |
||
75 | * @group functional |
||
76 | */ |
||
77 | View Code Duplication | public function testTermsAggregation(): void |
|
89 | |||
90 | /** |
||
91 | * @group functional |
||
92 | */ |
||
93 | View Code Duplication | public function testTermsSetOrder(): void |
|
105 | |||
106 | View Code Duplication | public function testTermsWithMissingAggregation(): void |
|
119 | |||
120 | /** |
||
121 | * @group functional |
||
122 | */ |
||
123 | public function testTermsSetOrders(): void |
||
140 | |||
141 | View Code Duplication | private function getIndex(): Index |
|
162 | } |
||
163 |
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.