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 |
||
17 | View Code Duplication | class Atomic_Additional_CSS_Manager { |
|
|
|||
18 | |||
19 | /** |
||
20 | * The site domain. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | private $domain; |
||
25 | |||
26 | /** |
||
27 | * Atomic_Additional_CSS_Manager constructor. |
||
28 | * |
||
29 | * @param string $domain the Site domain. |
||
30 | */ |
||
31 | public function __construct( $domain ) { |
||
34 | |||
35 | /** |
||
36 | * Replace the Additional CSS section from Customiz¡er with an upgrade nudge. |
||
37 | * |
||
38 | * @param \WP_Customize_Manager $wp_customize_manager Core customize manager. |
||
39 | */ |
||
40 | public function register_nudge( \WP_Customize_Manager $wp_customize_manager ) { |
||
52 | |||
53 | /** |
||
54 | * Get the Nudge URL. |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | private function get_nudge_url() { |
||
61 | } |
||
62 |
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.