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 | class WpHydraReplaceDomainTest extends WP_UnitTestCase { |
||
12 | /** |
||
13 | * Test setup |
||
14 | */ |
||
15 | public function setUp() { |
||
18 | |||
19 | /** |
||
20 | * Test teardown |
||
21 | */ |
||
22 | public function tearDown() { |
||
25 | |||
26 | /** |
||
27 | * Test with HTTP URL and HTTPS off. |
||
28 | * |
||
29 | * @covers WP_Hydra::replace_domain |
||
30 | */ |
||
31 | View Code Duplication | public function testWithHttpUrlAndHttpsOff() { |
|
40 | |||
41 | /** |
||
42 | * Test with HTTP URL and HTTPS on. |
||
43 | * |
||
44 | * @covers WP_Hydra::replace_domain |
||
45 | */ |
||
46 | View Code Duplication | public function testWithHttpUrlAndHttpsOn() { |
|
56 | |||
57 | /** |
||
58 | * Test with HTTPS URL and HTTPS off. |
||
59 | * |
||
60 | * @covers WP_Hydra::replace_domain |
||
61 | */ |
||
62 | View Code Duplication | public function testWithHttpsUrlAndHttpsOff() { |
|
72 | |||
73 | /** |
||
74 | * Test with HTTPS URL and HTTPS on. |
||
75 | * |
||
76 | * @covers WP_Hydra::replace_domain |
||
77 | */ |
||
78 | View Code Duplication | public function testWithHttpsUrlAndHttpsOn() { |
|
87 | |||
88 | /** |
||
89 | * Test with HTTP URL and HTTPS off and different domain. |
||
90 | * |
||
91 | * @covers WP_Hydra::replace_domain |
||
92 | */ |
||
93 | View Code Duplication | public function testWithHttpUrlAndHttpsOffAndDifferentDomain() { |
|
103 | |||
104 | /** |
||
105 | * Test with HTTP URL and HTTPS on and different domain. |
||
106 | * |
||
107 | * @covers WP_Hydra::replace_domain |
||
108 | */ |
||
109 | View Code Duplication | public function testWithHttpUrlAndHttpsOnAndDifferentDomain() { |
|
119 | |||
120 | /** |
||
121 | * Test with HTTPS URL and HTTPS off and different domain. |
||
122 | * |
||
123 | * @covers WP_Hydra::replace_domain |
||
124 | */ |
||
125 | View Code Duplication | public function testWithHttpsUrlAndHttpsOffAndDifferentDomain() { |
|
135 | |||
136 | /** |
||
137 | * Test with HTTPS URL and HTTPS on and different domain. |
||
138 | * |
||
139 | * @covers WP_Hydra::replace_domain |
||
140 | */ |
||
141 | View Code Duplication | public function testWithHttpsUrlAndHttpsOnAndDifferentDomain() { |
|
151 | |||
152 | } |
||
153 | |||
170 |
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.