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 JS URLs to be displayed before the HTML </body> tag |
||
53 | * @var array $footer_js |
||
54 | */ |
||
55 | protected $footer_js = array(); |
||
56 | |||
57 | /* |
||
58 | * an array of JSON vars to be set in the HTML header. |
||
59 | * @var array $localized_vars |
||
60 | */ |
||
61 | protected $localized_vars = array(); |
||
62 | |||
63 | |||
64 | |||
65 | /** |
||
66 | * Iframe constructor |
||
67 | * |
||
68 | * @param string $title |
||
69 | * @param string $content |
||
70 | * @throws \EE_Error |
||
71 | */ |
||
72 | public function __construct($title, $content) |
||
103 | |||
104 | |||
105 | |||
106 | /** |
||
107 | * @param string $title |
||
108 | * @throws \EE_Error |
||
109 | */ |
||
110 | public function setTitle($title) |
||
119 | |||
120 | |||
121 | |||
122 | /** |
||
123 | * @param string $content |
||
124 | * @throws \EE_Error |
||
125 | */ |
||
126 | public function setContent($content) |
||
135 | |||
136 | |||
137 | |||
138 | /** |
||
139 | * @param boolean $enqueue_wp_assets |
||
140 | */ |
||
141 | public function setEnqueueWpAssets($enqueue_wp_assets) |
||
145 | |||
146 | |||
147 | |||
148 | /** |
||
149 | * @param array $stylesheets |
||
150 | * @throws \EE_Error |
||
151 | */ |
||
152 | public function addStylesheets(array $stylesheets) |
||
163 | |||
164 | |||
165 | |||
166 | /** |
||
167 | * @param array $scripts |
||
168 | * @param bool $add_to_header |
||
169 | * @throws \EE_Error |
||
170 | */ |
||
171 | public function addScripts(array $scripts, $add_to_header = false) |
||
186 | |||
187 | |||
188 | |||
189 | /** |
||
190 | * @param array $vars |
||
191 | * @param string $var_name |
||
192 | * @throws \EE_Error |
||
193 | */ |
||
194 | public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
||
213 | |||
214 | |||
215 | |||
216 | /** |
||
217 | * @return void |
||
218 | */ |
||
219 | public function display() |
||
224 | |||
225 | |||
226 | |||
227 | /** |
||
228 | * @return string |
||
229 | */ |
||
230 | public function getTemplate() |
||
272 | |||
273 | |||
274 | |||
275 | /** |
||
276 | * localizeJsonVars |
||
277 | * |
||
278 | * @return string |
||
279 | */ |
||
280 | public function localizeJsonVars() |
||
294 | |||
295 | |||
296 | |||
297 | /** |
||
298 | * Adds an iframe embed code button to the Event editor. |
||
299 | * |
||
300 | * @param string $route_name the named module route that generates the iframe |
||
301 | */ |
||
302 | public static function addEventEditorIframeEmbedButton($route_name) |
||
318 | |||
319 | |||
320 | |||
321 | /** |
||
322 | * iframe embed code button to the Event editor. |
||
323 | * |
||
324 | * @param string $permalink_string |
||
325 | * @param int $id |
||
326 | * @param string $new_title (unused) |
||
327 | * @param string $new_slug (unused) |
||
328 | * @param string $route_name the named module route that generates the iframe |
||
329 | * @return string |
||
330 | */ |
||
331 | public static function eventListIframeEmbedButton( |
||
354 | |||
355 | |||
356 | |||
357 | /** |
||
358 | * Adds an iframe embed code button to the Event editor. |
||
359 | * |
||
360 | * @param string $route_name the named module route that generates the iframe |
||
361 | */ |
||
362 | public static function addEventListIframeEmbedButton($route_name) |
||
387 | |||
388 | |||
389 | |||
390 | /** |
||
391 | * Adds an iframe embed code button via a WP do_action() as determined by the first parameter |
||
392 | * |
||
393 | * @param string $iframe_name |
||
394 | * @param string $route_name the named module route that generates the iframe |
||
395 | * @param string $action name of the WP do_action() to hook into |
||
396 | */ |
||
397 | public static function addActionIframeEmbedButton($iframe_name, $route_name, $action) |
||
408 | |||
409 | |||
410 | |||
411 | /** |
||
412 | * iframe_embed_html |
||
413 | * |
||
414 | * @param string $iframe_name |
||
415 | * @param string $route_name the named module route that generates the iframe |
||
416 | * @param array $query_args |
||
417 | * @param string $button_class |
||
418 | * @return string |
||
419 | */ |
||
420 | public static function embedButtonHtml($iframe_name, $route_name, $query_args = array(), $button_class = '') |
||
452 | |||
453 | |||
454 | |||
455 | /** |
||
456 | * iframe button js on admin events list or event editor page |
||
457 | */ |
||
458 | public static function EventsAdminEmbedButtonAssets() |
||
468 | |||
469 | |||
470 | |||
471 | /** |
||
472 | * enqueue iframe button js |
||
473 | */ |
||
474 | View Code Duplication | public static function embedButtonAssets() |
|
489 | |||
490 | |||
491 | |||
492 | } |
||
493 | // End of file Iframe.php |
||
494 | // Location: /Iframe.php |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.