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 |
||
| 6 | class MetaFlexSlider extends MetaSlider |
||
|
|
|||
| 7 | { |
||
| 8 | protected $js_function = 'flexslider'; |
||
| 9 | protected $js_path = 'sliders/flexslider/jquery.flexslider-min.js'; |
||
| 10 | protected $css_path = 'sliders/flexslider/flexslider.css'; |
||
| 11 | protected $carousel_item_margin = 5; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Constructor |
||
| 15 | * |
||
| 16 | * @param integer $id slideshow ID |
||
| 17 | * @param $shortcode_settings |
||
| 18 | */ |
||
| 19 | public function __construct($id, $shortcode_settings) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Adjust the slider parameters so they're comparible with the carousel mode |
||
| 33 | * |
||
| 34 | * @param array $options |
||
| 35 | * @param integer $slider_id |
||
| 36 | * @return array $options |
||
| 37 | */ |
||
| 38 | public function enable_carousel_mode($options, $slider_id) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Ensure CSS transitions are disabled when easing is enabled. |
||
| 60 | * |
||
| 61 | * @param array $options |
||
| 62 | * @param integer $slider_id |
||
| 63 | * @return array $options |
||
| 64 | */ |
||
| 65 | public function enable_easing($options, $slider_id) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Add a 'nav-hidden' class to slideshows where the navigation is hidden. |
||
| 79 | * |
||
| 80 | * @param $class |
||
| 81 | * @param $id |
||
| 82 | * @param array $settings |
||
| 83 | * @return string $css |
||
| 84 | * @internal param string $css |
||
| 85 | * @internal param int $slider_id |
||
| 86 | */ |
||
| 87 | public function remove_bottom_margin($class, $id, $settings) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Return css to ensure our slides are rendered correctly in the carousel |
||
| 101 | * |
||
| 102 | * @param string $css |
||
| 103 | * @param array $settings |
||
| 104 | * @param integer $slider_id |
||
| 105 | * @return string $css |
||
| 106 | */ |
||
| 107 | public function get_carousel_css($css, $settings, $slider_id) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Enable the parameters that are accepted by the slider |
||
| 121 | * |
||
| 122 | * @param string $param |
||
| 123 | * @return array|boolean enabled parameters (false if parameter doesn't exist) |
||
| 124 | */ |
||
| 125 | View Code Duplication | protected function get_param($param) |
|
| 149 | |||
| 150 | /** |
||
| 151 | * Include slider assets |
||
| 152 | */ |
||
| 153 | public function enqueue_scripts() |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Build the HTML for a slider. |
||
| 164 | * |
||
| 165 | * @return string slider markup. |
||
| 166 | */ |
||
| 167 | protected function get_html() |
||
| 190 | } |
||
| 191 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.