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 WpHydraSetupUploadDirTest extends WP_UnitTestCase { |
||
12 | /** |
||
13 | * Test setup |
||
14 | */ |
||
15 | public function setUp() { |
||
20 | |||
21 | /** |
||
22 | * Test teardown |
||
23 | */ |
||
24 | public function tearDown() { |
||
29 | |||
30 | /** |
||
31 | * Test the filter on URLs. |
||
32 | * |
||
33 | * @covers WP_Hydra::setup_upload_dir |
||
34 | */ |
||
35 | View Code Duplication | public function testFilterOnUrls() { |
|
47 | |||
48 | /** |
||
49 | * Test the filter on another field. |
||
50 | * |
||
51 | * @covers WP_Hydra::setup_upload_dir |
||
52 | */ |
||
53 | View Code Duplication | public function testFilterOnSomethingElse() { |
|
63 | |||
64 | /** |
||
65 | * Used for hooking on the wp_hydra_domain filter. |
||
66 | * |
||
67 | * @param string $domain The domain. |
||
68 | * @return string A different domain domain. |
||
69 | */ |
||
70 | public function wp_hydra_domain( $domain ) { |
||
73 | |||
74 | } |
||
75 |
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.