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 |
||
11 | class ZillowWidgets { |
||
12 | |||
13 | /** |
||
14 | * __construct function. |
||
15 | * |
||
16 | * @access public |
||
17 | * @return void |
||
18 | */ |
||
19 | public function __construct() { |
||
21 | |||
22 | |||
23 | /** |
||
24 | * zillow_iframe_css function. |
||
25 | * |
||
26 | * @access public |
||
27 | * @return void |
||
28 | */ |
||
29 | public function zillow_iframe_css() { |
||
43 | |||
44 | /** |
||
45 | * Zillow Iframe ID Names. |
||
46 | * |
||
47 | * @access public |
||
48 | * @param string $iframe_id (default: '') |
||
49 | * @return void |
||
50 | */ |
||
51 | public function zillow_iframe_id( $iframe_id = '' ) { |
||
58 | |||
59 | /** |
||
60 | * Zillow Iframe Class Names. |
||
61 | * |
||
62 | * @access public |
||
63 | * @param string $widget_name (default: '') |
||
64 | * @return void |
||
65 | */ |
||
66 | View Code Duplication | public function zillow_iframe_class( $widget_name = '' ) { |
|
75 | |||
76 | /* YOU ON ZILLOW WIDGETS. */ |
||
77 | |||
78 | /** |
||
79 | * Get My Zillow Listings Widget. |
||
80 | * |
||
81 | * @access public |
||
82 | * @param string $iframe_id (default: '') |
||
83 | * @param mixed $zuid |
||
84 | * @param string $format (default: 'normalWidget') |
||
85 | * @return void |
||
86 | */ |
||
87 | public function get_listings_widget( $iframe_id = '', $zuid, $format = 'normalWidget' ) { |
||
92 | |||
93 | /** |
||
94 | * Get Review Widget (https://www.zillow.com/webtools/widgets/review-widget/). |
||
95 | * |
||
96 | * @access public |
||
97 | * @param string $iframe_id (default: '') |
||
98 | * @param mixed $zuid |
||
99 | * @param mixed $screenname |
||
100 | * @param string $size (default: 'wide') |
||
101 | * @param string $zmod (default: 'true') |
||
102 | * @param mixed $width |
||
103 | * @param mixed $height |
||
104 | * @return void |
||
105 | */ |
||
106 | public function get_review_widget( $iframe_id = '', $zuid, $screenname, $size = 'wide', $zmod = 'true', $width = '300', $height = '100' ) { |
||
111 | |||
112 | /** |
||
113 | * Get My Past Sales Widget. |
||
114 | * |
||
115 | * @access public |
||
116 | * @param string $iframe_id (default: '') |
||
117 | * @param mixed $zuid |
||
118 | * @param string $format (default: 'normalWidget') |
||
119 | * @return void |
||
120 | */ |
||
121 | public function get_past_listings_widget( $iframe_id = '', $zuid, $format = 'normalWidget' ) { |
||
126 | |||
127 | /** |
||
128 | * Get Contact Form Widget. |
||
129 | * |
||
130 | * @access public |
||
131 | * @param string $iframe_id (default: '') |
||
132 | * @param mixed $email |
||
133 | * @return void |
||
134 | */ |
||
135 | public function get_contact_widget( $iframe_id = '', $email ) { |
||
140 | |||
141 | /* MORTGAGE WIDGETS */ |
||
142 | |||
143 | /** |
||
144 | * Get Affordability Calculator. |
||
145 | * |
||
146 | * @access public |
||
147 | * @param string $iframe_id (default: '') |
||
148 | * @return void |
||
149 | */ |
||
150 | public function get_affordability_calc_widget( $iframe_id = '' ) { |
||
155 | |||
156 | /** |
||
157 | * Get Monthly Payment Calculator. |
||
158 | * |
||
159 | * @access public |
||
160 | * @param string $iframe_id (default: '') |
||
161 | * @return void |
||
162 | */ |
||
163 | public function get_monthlypay_calc_widget( $iframe_id = '' ) { |
||
168 | |||
169 | /** |
||
170 | * Get Mortgage Calculator Widget. |
||
171 | * |
||
172 | * @access public |
||
173 | * @param string $iframe_id (default: '') |
||
174 | * @param string $orientation (default: 'verticalWidget') |
||
175 | * @return void |
||
176 | */ |
||
177 | public function get_mortgage_calc_widget( $iframe_id = '', $orientation = 'verticalWidget' ) { |
||
190 | |||
191 | /** |
||
192 | * Get Mortgage Rate Table Widget. |
||
193 | * |
||
194 | * @access public |
||
195 | * @param string $iframe_id (default: '') |
||
196 | * @param mixed $textcolor |
||
197 | * @param mixed $screenname |
||
198 | * @param mixed $region |
||
199 | * @return void |
||
200 | */ |
||
201 | public function get_mortgage_rate_table_widget( $iframe_id = '', $textcolor, $screenname, $region ) { |
||
240 | |||
241 | /** |
||
242 | * Get Rate Table with Graph Widget. |
||
243 | * |
||
244 | * @access public |
||
245 | * @param string $iframe_id (default: '') |
||
246 | * @return void |
||
247 | */ |
||
248 | public function get_rate_table_graph_widget( $iframe_id = '' ) { |
||
253 | |||
254 | /** |
||
255 | * Get Large Rate Table Widget. |
||
256 | * |
||
257 | * @access public |
||
258 | * @return void |
||
259 | */ |
||
260 | public function get_mortage_rate_widget( $iframe_id = '' ) { |
||
265 | |||
266 | /** |
||
267 | * Get Payment Breakout Calculator Widget. |
||
268 | * |
||
269 | * @access public |
||
270 | * @param string $iframe_id (default: '') |
||
271 | * @param mixed $price |
||
272 | * @param mixed $region_id |
||
273 | * @param string $textcolor (default: '000000') |
||
274 | * @return void |
||
275 | */ |
||
276 | public function get_paymentbreakout_calc_widget( $iframe_id = '', $price, $region_id, $textcolor = '000000' ) { |
||
281 | |||
282 | /* DATA AND STATS. */ |
||
283 | |||
284 | /** |
||
285 | * Get Home Value Estimate Chart Widget. |
||
286 | * |
||
287 | * @access public |
||
288 | * @param string $iframe_id (default: '') |
||
289 | * @param string $type (default: 'iframe') |
||
290 | * @param mixed $address |
||
291 | * @param string $searchbox (default: 'yes') |
||
292 | * @param mixed $region |
||
293 | * @param string $skinny_widget (default: 'true') |
||
294 | * @param string $textcolor (default: '000000') |
||
295 | * @param string $bgcolor (default: 'FFFFFF') |
||
296 | * @return void |
||
297 | */ |
||
298 | public function get_home_value_estimate_widget( $iframe_id = '', $type = 'iframe', $address, $searchbox = 'yes', $region, $skinny_widget = 'true', $textcolor = '000000', $bgcolor = 'FFFFFF' ) { |
||
302 | |||
303 | /** |
||
304 | * get_realestate_stats_widget function. |
||
305 | * |
||
306 | * @access public |
||
307 | * @param string $iframe_id (default: '') |
||
308 | * @param mixed $cs |
||
309 | * @param string $did (default: 'rsw-wide') |
||
310 | * @param mixed $dys |
||
311 | * @param mixed $mt |
||
312 | * @param mixed $region_id |
||
313 | * @param mixed $sid |
||
314 | * @param string $type (default: 'iframe') |
||
315 | * @param string $wtype (default: 'rhv') |
||
316 | * @param string $skinny_widget (default: 'true') |
||
317 | * @param string $textcolor (default: '000000') |
||
318 | * @param string $bgcolor (default: 'FFFFFF') |
||
319 | * @return void |
||
320 | */ |
||
321 | public function get_realestate_stats_widget( $iframe_id = '', $cs, $did = 'rsw-wide', $dys, $mt, $region_id, $sid, $type = 'iframe', $wtype = 'rhv', $skinny_widget = 'true', $textcolor = '000000', $bgcolor = 'FFFFFF' ) { |
||
325 | |||
326 | /** |
||
327 | * get_rent_validation_widget function. |
||
328 | * |
||
329 | * @access public |
||
330 | * @param string $iframe_id (default: '') |
||
331 | * @param string $type (default: 'iframe') |
||
332 | * @param string $skinny_widget (default: 'true') |
||
333 | * @param string $searchbox (default: 'yes') |
||
334 | * @param string $for_rent (default: 'true') |
||
335 | * @param mixed $address |
||
336 | * @param mixed $region |
||
337 | * @param string $textcolor (default: '000000') |
||
338 | * @param string $bgcolor (default: 'FFFFF') |
||
339 | * @return void |
||
340 | */ |
||
341 | public function get_rent_validation_widget($iframe_id = '', $type = 'iframe', $skinny_widget = 'true', $searchbox = 'yes', $for_rent = 'true', $address, $region, $textcolor = '000000', $bgcolor = 'FFFFF' ) { |
||
345 | |||
346 | /* LISTINGS. */ |
||
347 | |||
348 | /** |
||
349 | * Get Most Expensive Homes Widget. |
||
350 | * |
||
351 | * @access public |
||
352 | * @param string $iframe_id (default: '') |
||
353 | * @param mixed $location |
||
354 | * @param string $type (default: 'iframe') |
||
355 | * @param string $size (default: ' wide') |
||
356 | * @return void |
||
357 | */ |
||
358 | View Code Duplication | public function get_expensive_homes_widget( $iframe_id = '', $location, $type = 'iframe', $size = ' wide' ) { |
|
371 | |||
372 | /** |
||
373 | * Get Newest For Sale Homes Widget. |
||
374 | * |
||
375 | * @access public |
||
376 | * @param string $iframe_id (default: '') |
||
377 | * @param mixed $location |
||
378 | * @param string $type (default: 'iframe') |
||
379 | * @param string $size (default: ' wide') |
||
380 | * @return void |
||
381 | */ |
||
382 | View Code Duplication | public function get_newest_forsale_homes_widget( $iframe_id = '', $location, $type = 'iframe', $size = ' wide' ) { |
|
393 | |||
394 | /** |
||
395 | * get_zillow_search_widget function. |
||
396 | * |
||
397 | * @access public |
||
398 | * @param string $iframe_id (default: '') |
||
399 | * @param string $use_user_location (default: 'false') |
||
400 | * @param string $is_public (default: 'true') |
||
401 | * @param string $bucket (default: 'map') |
||
402 | * @param mixed $zillow_screenname |
||
403 | * @param mixed $region_id |
||
404 | * @return void |
||
405 | */ |
||
406 | public function get_zillow_search_widget( $iframe_id = '', $use_user_location = 'false', $is_public = 'true', $bucket = 'map', $zillow_screenname, $region_id ) { |
||
411 | |||
412 | /** |
||
413 | * get_lg_zillow_search_widget function. |
||
414 | * |
||
415 | * @access public |
||
416 | * @param string $widget_type (default: 'iframe') |
||
417 | * @param string $iframe_id (default: '') |
||
418 | * @param mixed $zillow_screenname |
||
419 | * @param string $type (default: 'iframe') |
||
420 | * @param mixed $region_name |
||
421 | * @param string $include_home_val_info (default: 'yes') |
||
422 | * @return void |
||
423 | */ |
||
424 | View Code Duplication | public function get_lg_zillow_search_widget( $iframe_id = '', $zillow_screenname, $type = 'iframe', $region_name, $include_home_val_info = 'yes' ) { |
|
434 | |||
435 | /* POLLS & QUIZZES. */ |
||
436 | |||
437 | /** |
||
438 | * get_refinance_quiz_widget function. |
||
439 | * |
||
440 | * @access public |
||
441 | * @param string $widget_type (default: 'iframe') |
||
442 | * @param string $iframe_id (default: '') |
||
443 | * @param string $type (default: 'iframe') |
||
444 | * @param string $widgetcode (default: 'refq') |
||
445 | * @param mixed $zillow_screenname |
||
446 | * @return void |
||
447 | */ |
||
448 | public function get_refinance_quiz_widget( $widget_type = 'iframe', $iframe_id = '', $type = 'iframe', $widgetcode = 'refq', $zillow_screenname ) { |
||
453 | |||
454 | /** |
||
455 | * get_kindofneighbor_quiz_widget function. |
||
456 | * |
||
457 | * @access public |
||
458 | * @param string $widget_type (default: 'iframe') |
||
459 | * @param string $iframe_id (default: '') |
||
460 | * @param string $type (default: 'iframe') |
||
461 | * @param string $widgetcode (default: 'konq') |
||
462 | * @param mixed $zillow_screenname |
||
463 | * @return void |
||
464 | */ |
||
465 | public function get_kindofneighbor_quiz_widget( $widget_type = 'iframe', $iframe_id = '', $type = 'iframe', $widgetcode = 'konq', $zillow_screenname ) { |
||
470 | |||
471 | /** |
||
472 | * get_mortgage_quiz function. |
||
473 | * |
||
474 | * @access public |
||
475 | * @param string $widget_type (default: 'iframe') |
||
476 | * @param string $iframe_id (default: '') |
||
477 | * @param string $type (default: 'iframe') |
||
478 | * @param string $widgetcode (default: 'mq') |
||
479 | * @param mixed $zillow_screenname |
||
480 | * @return void |
||
481 | */ |
||
482 | public function get_mortgage_quiz( $widget_type = 'iframe', $iframe_id = '', $type = 'iframe', $widgetcode = 'mq', $zillow_screenname ) { |
||
487 | |||
488 | /** |
||
489 | * get_mortgage_harp_quiz function. |
||
490 | * |
||
491 | * @access public |
||
492 | * @param string $widget_type (default: 'iframe') |
||
493 | * @param string $iframe_id (default: '') |
||
494 | * @param string $type (default: 'iframe') |
||
495 | * @param string $widgetcode (default: 'hec') |
||
496 | * @param mixed $zillow_screenname |
||
497 | * @return void |
||
498 | */ |
||
499 | public function get_mortgage_harp_quiz( $widget_type = 'iframe', $iframe_id = '', $type = 'iframe', $widgetcode = 'hec', $zillow_screenname ) { |
||
504 | |||
505 | /** |
||
506 | * get_buyeriq_quiz function. |
||
507 | * |
||
508 | * @access public |
||
509 | * @param string $widget_type (default: 'iframe') |
||
510 | * @param string $iframe_id (default: '') |
||
511 | * @param string $type (default: 'iframe') |
||
512 | * @param string $widgetcode (default: 'biq') |
||
513 | * @param mixed $zillow_screenname |
||
514 | * @return void |
||
515 | */ |
||
516 | public function get_buyeriq_quiz( $widget_type = 'iframe', $iframe_id = '', $type = 'iframe', $widgetcode = 'biq', $zillow_screenname ) { |
||
521 | |||
522 | /* MISCELLANEOUS. */ |
||
523 | |||
524 | /** |
||
525 | * get_moving_boxes_widget function. |
||
526 | * |
||
527 | * @access public |
||
528 | * @param string $iframe_id (default: '') |
||
529 | * @param mixed $zillow_city_id |
||
530 | * @param mixed $button_text |
||
531 | * @param mixed $custom_text |
||
532 | * @param mixed $button_link |
||
533 | * @return void |
||
534 | */ |
||
535 | public function get_moving_boxes_widget( $widget_type = 'iframe', $iframe_id = '', $zillow_city_id, $button_text, $custom_text, $button_link ) { |
||
540 | |||
541 | } |
||
542 | } |
||
543 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.