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 |
||
18 | class Iframe |
||
19 | { |
||
20 | |||
21 | /* |
||
22 | * HTML for notices and ajax gif |
||
23 | * @var string $title |
||
24 | */ |
||
25 | protected $title = ''; |
||
26 | |||
27 | /* |
||
28 | * HTML for the content being displayed |
||
29 | * @var string $content |
||
30 | */ |
||
31 | protected $content = ''; |
||
32 | |||
33 | /* |
||
34 | * whether or not to call wp_head() and wp_footer() |
||
35 | * @var boolean $enqueue_wp_assets |
||
36 | */ |
||
37 | protected $enqueue_wp_assets = false; |
||
38 | |||
39 | /* |
||
40 | * an array of CSS URLs |
||
41 | * @var array $css |
||
42 | */ |
||
43 | protected $css = array(); |
||
44 | |||
45 | /* |
||
46 | * an array of JS URLs to be set in the HTML header. |
||
47 | * @var array $header_js |
||
48 | */ |
||
49 | protected $header_js = array(); |
||
50 | |||
51 | /* |
||
52 | * an array of additional attributes to be added to <script> tags for header JS |
||
53 | * @var array $footer_js |
||
54 | */ |
||
55 | protected $header_js_attributes = array(); |
||
56 | |||
57 | /* |
||
58 | * an array of JS URLs to be displayed before the HTML </body> tag |
||
59 | * @var array $footer_js |
||
60 | */ |
||
61 | protected $footer_js = array(); |
||
62 | |||
63 | /* |
||
64 | * an array of additional attributes to be added to <script> tags for footer JS |
||
65 | * @var array $footer_js_attributes |
||
66 | */ |
||
67 | protected $footer_js_attributes = array(); |
||
68 | |||
69 | /* |
||
70 | * an array of JSON vars to be set in the HTML header. |
||
71 | * @var array $localized_vars |
||
72 | */ |
||
73 | protected $localized_vars = array(); |
||
74 | |||
75 | |||
76 | /** |
||
77 | * Iframe constructor |
||
78 | * |
||
79 | * @param string $title |
||
80 | * @param string $content |
||
81 | * @throws DomainException |
||
82 | */ |
||
83 | public function __construct($title, $content) |
||
128 | |||
129 | |||
130 | /** |
||
131 | * @param string $title |
||
132 | * @throws DomainException |
||
133 | */ |
||
134 | public function setTitle($title) |
||
143 | |||
144 | |||
145 | /** |
||
146 | * @param string $content |
||
147 | * @throws DomainException |
||
148 | */ |
||
149 | public function setContent($content) |
||
158 | |||
159 | |||
160 | /** |
||
161 | * @param boolean $enqueue_wp_assets |
||
162 | */ |
||
163 | public function setEnqueueWpAssets($enqueue_wp_assets) |
||
167 | |||
168 | |||
169 | /** |
||
170 | * @param array $stylesheets |
||
171 | * @throws DomainException |
||
172 | */ |
||
173 | public function addStylesheets(array $stylesheets) |
||
187 | |||
188 | |||
189 | /** |
||
190 | * @param array $scripts |
||
191 | * @param bool $add_to_header |
||
192 | * @throws DomainException |
||
193 | */ |
||
194 | View Code Duplication | public function addScripts(array $scripts, $add_to_header = false) |
|
212 | |||
213 | |||
214 | /** |
||
215 | * @param array $script_attributes |
||
216 | * @param bool $add_to_header |
||
217 | * @throws DomainException |
||
218 | */ |
||
219 | View Code Duplication | public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
237 | |||
238 | |||
239 | /** |
||
240 | * @param array $vars |
||
241 | * @param string $var_name |
||
242 | * @throws DomainException |
||
243 | */ |
||
244 | public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
||
267 | |||
268 | |||
269 | /** |
||
270 | * @param string $utm_content |
||
271 | * @throws DomainException |
||
272 | */ |
||
273 | public function display($utm_content = '') |
||
284 | |||
285 | |||
286 | /** |
||
287 | * @return string |
||
288 | * @throws DomainException |
||
289 | */ |
||
290 | public function getTemplate() |
||
350 | |||
351 | |||
352 | /** |
||
353 | * localizeJsonVars |
||
354 | * |
||
355 | * @return string |
||
356 | */ |
||
357 | public function localizeJsonVars() |
||
368 | |||
369 | |||
370 | /** |
||
371 | * @param bool|int|float|string|array $var |
||
372 | * @return array |
||
373 | */ |
||
374 | public function encodeJsonVars($var) |
||
388 | } |
||
389 |