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 |
||
19 | class DateRangePicker extends Filter |
||
20 | { |
||
21 | protected $js_options; |
||
22 | |||
23 | protected $use_clear_button; |
||
24 | |||
25 | protected $template = '*.components.filters.date_range_picker'; |
||
26 | |||
27 | protected $is_submitted_on_change = false; |
||
28 | |||
29 | /** |
||
30 | * Returns javascript options |
||
31 | * |
||
32 | * Available options: |
||
33 | * @see https://github.com/dangrossman/bootstrap-daterangepicker#options |
||
34 | * |
||
35 | * @return array |
||
36 | */ |
||
37 | public function getJsOptions() |
||
44 | |||
45 | /** |
||
46 | * Sets javascript options |
||
47 | * |
||
48 | * Available options: |
||
49 | * @see https://github.com/dangrossman/bootstrap-daterangepicker#options |
||
50 | * |
||
51 | * @param array $options |
||
52 | */ |
||
53 | public function setJsOptions($options) |
||
58 | |||
59 | /** |
||
60 | * Returns true if form must be submitted immediately |
||
61 | * when filter value selected. |
||
62 | * |
||
63 | * @return bool |
||
64 | */ |
||
65 | public function isSubmittedOnChange() |
||
69 | |||
70 | /** |
||
71 | * Allows to submit form immediately when filter value selected. |
||
72 | * |
||
73 | * @param bool $isSubmittedOnChange |
||
74 | * @return $this |
||
75 | */ |
||
76 | public function setSubmittedOnChange($isSubmittedOnChange) |
||
81 | |||
82 | View Code Duplication | public function getStartValue() |
|
94 | |||
95 | |||
96 | View Code Duplication | public function getEndValue() |
|
108 | |||
109 | public function getValue() |
||
113 | |||
114 | /** |
||
115 | * Returns true if non-empty value specified for the filter. |
||
116 | * |
||
117 | * @return bool |
||
118 | */ |
||
119 | protected function hasValue() |
||
124 | |||
125 | /** |
||
126 | * Returns default javascript options |
||
127 | * |
||
128 | * Available options: |
||
129 | * @see https://github.com/dangrossman/bootstrap-daterangepicker#options |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | protected function getDefaultJsOptions() |
||
181 | |||
182 | public function getDefaultStartValue() |
||
186 | |||
187 | public function getDefaultEndValue() |
||
191 | |||
192 | /** |
||
193 | * Returns default filter value as [$startDate, $endDate] |
||
194 | * |
||
195 | * @return array |
||
196 | */ |
||
197 | public function getDefaultValue() |
||
204 | |||
205 | public function getStartInputName() |
||
210 | |||
211 | public function getEndInputName() |
||
216 | |||
217 | public function getFilteringFunc() |
||
224 | |||
225 | protected function getDefaultFilteringFunc() |
||
232 | } |
||
233 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.