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 |
||
23 | class Iframe |
||
24 | { |
||
25 | |||
26 | /* |
||
27 | * HTML for notices and ajax gif |
||
28 | * @var string $title |
||
29 | */ |
||
30 | protected $title = ''; |
||
31 | |||
32 | /* |
||
33 | * HTML for the content being displayed |
||
34 | * @var string $content |
||
35 | */ |
||
36 | protected $content = ''; |
||
37 | |||
38 | /* |
||
39 | * whether or not to call wp_head() and wp_footer() |
||
40 | * @var boolean $enqueue_wp_assets |
||
41 | */ |
||
42 | protected $enqueue_wp_assets = false; |
||
43 | |||
44 | /* |
||
45 | * an array of CSS URLs |
||
46 | * @var array $css |
||
47 | */ |
||
48 | protected $css = array(); |
||
49 | |||
50 | /* |
||
51 | * an array of JS URLs to be set in the HTML header. |
||
52 | * @var array $header_js |
||
53 | */ |
||
54 | protected $header_js = array(); |
||
55 | |||
56 | /* |
||
57 | * an array of additional attributes to be added to <script> tags for header JS |
||
58 | * @var array $footer_js |
||
59 | */ |
||
60 | protected $header_js_attributes = array(); |
||
61 | |||
62 | /* |
||
63 | * an array of JS URLs to be displayed before the HTML </body> tag |
||
64 | * @var array $footer_js |
||
65 | */ |
||
66 | protected $footer_js = array(); |
||
67 | |||
68 | /* |
||
69 | * an array of additional attributes to be added to <script> tags for footer JS |
||
70 | * @var array $footer_js_attributes |
||
71 | */ |
||
72 | protected $footer_js_attributes = array(); |
||
73 | |||
74 | /* |
||
75 | * an array of JSON vars to be set in the HTML header. |
||
76 | * @var array $localized_vars |
||
77 | */ |
||
78 | protected $localized_vars = array(); |
||
79 | |||
80 | |||
81 | |||
82 | /** |
||
83 | * Iframe constructor |
||
84 | * |
||
85 | * @param string $title |
||
86 | * @param string $content |
||
87 | * @throws DomainException |
||
88 | */ |
||
89 | public function __construct( $title, $content ) |
||
136 | |||
137 | |||
138 | |||
139 | /** |
||
140 | * @param string $title |
||
141 | * @throws DomainException |
||
142 | */ |
||
143 | public function setTitle( $title ) |
||
152 | |||
153 | |||
154 | |||
155 | /** |
||
156 | * @param string $content |
||
157 | * @throws DomainException |
||
158 | */ |
||
159 | public function setContent( $content ) |
||
168 | |||
169 | |||
170 | |||
171 | /** |
||
172 | * @param boolean $enqueue_wp_assets |
||
173 | */ |
||
174 | public function setEnqueueWpAssets( $enqueue_wp_assets ) |
||
178 | |||
179 | |||
180 | |||
181 | /** |
||
182 | * @param array $stylesheets |
||
183 | * @throws DomainException |
||
184 | */ |
||
185 | public function addStylesheets( array $stylesheets ) |
||
199 | |||
200 | |||
201 | |||
202 | /** |
||
203 | * @param array $scripts |
||
204 | * @param bool $add_to_header |
||
205 | * @throws DomainException |
||
206 | */ |
||
207 | View Code Duplication | public function addScripts( array $scripts, $add_to_header = false ) |
|
225 | |||
226 | |||
227 | |||
228 | /** |
||
229 | * @param array $script_attributes |
||
230 | * @param bool $add_to_header |
||
231 | * @throws DomainException |
||
232 | */ |
||
233 | View Code Duplication | public function addScriptAttributes( array $script_attributes, $add_to_header = false ) |
|
251 | |||
252 | |||
253 | |||
254 | /** |
||
255 | * @param array $vars |
||
256 | * @param string $var_name |
||
257 | * @throws DomainException |
||
258 | */ |
||
259 | public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
||
282 | |||
283 | |||
284 | |||
285 | /** |
||
286 | * @param string $utm_content |
||
287 | * @throws DomainException |
||
288 | */ |
||
289 | public function display($utm_content = '') |
||
300 | |||
301 | |||
302 | |||
303 | /** |
||
304 | * @return string |
||
305 | * @throws DomainException |
||
306 | */ |
||
307 | public function getTemplate() |
||
367 | |||
368 | |||
369 | |||
370 | /** |
||
371 | * localizeJsonVars |
||
372 | * |
||
373 | * @return string |
||
374 | */ |
||
375 | public function localizeJsonVars() |
||
386 | |||
387 | |||
388 | |||
389 | /** |
||
390 | * @param bool|int|float|string|array $var |
||
391 | * @return array |
||
392 | */ |
||
393 | public function encodeJsonVars( $var ) |
||
407 | |||
408 | |||
409 | |||
410 | } |
||
411 | // End of file Iframe.php |
||
413 |