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 |
||
22 | View Code Duplication | class Test_Atomic_Additional_CSS_Manager extends \WP_UnitTestCase { |
|
|
|||
23 | /** |
||
24 | * A mock Customize manager. |
||
25 | * |
||
26 | * @var \WP_Customize_Manager |
||
27 | */ |
||
28 | private $wp_customize; |
||
29 | |||
30 | /** |
||
31 | * Register a customizer manager. |
||
32 | * |
||
33 | * @return void |
||
34 | */ |
||
35 | public function setUp() { |
||
40 | |||
41 | /** |
||
42 | * Check if the nudge contains the proper url and message copy. |
||
43 | */ |
||
44 | public function test_it_generates_proper_url_and_nudge() { |
||
57 | } |
||
58 |
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.