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 WpHydraSetupDomainTest 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 a wrong URL. |
||
28 | * |
||
29 | * @covers WP_Hydra::setup_domain |
||
30 | */ |
||
31 | public function testWithWrongURL() { |
||
38 | |||
39 | /** |
||
40 | * Test with a no host specified. |
||
41 | * |
||
42 | * @covers WP_Hydra::setup_domain |
||
43 | */ |
||
44 | View Code Duplication | public function testWithNoHost() { |
|
56 | |||
57 | /** |
||
58 | * Test with the same domain. |
||
59 | * |
||
60 | * @covers WP_Hydra::setup_domain |
||
61 | */ |
||
62 | View Code Duplication | public function testWithTheSameDomain() { |
|
74 | |||
75 | /** |
||
76 | * Test with a different domain. |
||
77 | * |
||
78 | * @covers WP_Hydra::setup_domain |
||
79 | */ |
||
80 | public function testWithDifferentDomain() { |
||
95 | |||
96 | } |
||
97 | |||
114 |
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.