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 |
||
16 | class CSS_Customizer_Nudge { |
||
17 | /** |
||
18 | * Call to Action URL. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | private $cta_url; |
||
23 | |||
24 | /** |
||
25 | * The nudge message. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | private $nudge_copy; |
||
30 | |||
31 | /** |
||
32 | * The name of the control in Customizer. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $control_name; |
||
37 | |||
38 | /** |
||
39 | * CSS_Customizer_Nudge constructor. |
||
40 | * |
||
41 | * @param string $cta_url The URL to the plans. |
||
42 | * @param string $nudge_copy The nudge text. |
||
43 | * @param string $control_name The slug prefix of the nudge. |
||
44 | */ |
||
45 | public function __construct( $cta_url, $nudge_copy, $control_name = 'custom_css' ) { |
||
50 | |||
51 | /** |
||
52 | * Register the assets required for the CSS nudge page from the Customizer. |
||
53 | */ |
||
54 | View Code Duplication | public function customize_controls_enqueue_scripts_nudge() { |
|
69 | |||
70 | /** |
||
71 | * Register the CSS nudge in the Customizer. |
||
72 | * |
||
73 | * @param \WP_Customize_Manager $wp_customize The customize manager. |
||
74 | */ |
||
75 | public function customize_register_nudge( \WP_Customize_Manager $wp_customize ) { |
||
92 | |||
93 | /** |
||
94 | * Create a nudge control object. |
||
95 | * |
||
96 | * @param \WP_Customize_Manager $wp_customize The Core Customize Manager. |
||
97 | * |
||
98 | * @return CSS_Nudge_Customize_Control |
||
99 | */ |
||
100 | public function create_css_nudge_control( \WP_Customize_Manager $wp_customize ) { |
||
113 | |||
114 | /** |
||
115 | * Create the nudge section. |
||
116 | * |
||
117 | * @param \WP_Customize_Manager $wp_customize The core Customize Manager. |
||
118 | * |
||
119 | * @return \WP_Customize_Section |
||
120 | */ |
||
121 | public function create_css_nudge_section( \WP_Customize_Manager $wp_customize ) { |
||
131 | } |
||
132 |