| Conditions | 2 |
| Paths | 2 |
| Total Lines | 70 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 168 | private function getElementJS() |
||
| 169 | { |
||
| 170 | $js = null; |
||
| 171 | $id = $this->getAttribute('id'); |
||
| 172 | |||
| 173 | $dateRange = $this->getValue(); |
||
| 174 | |||
| 175 | $defaultDate = ''; |
||
| 176 | $startTime = ''; |
||
| 177 | $endTime = ''; |
||
| 178 | if (!empty($dateRange)) { |
||
| 179 | $dates = $this->parseDateRange($dateRange); |
||
| 180 | $defaultDate = $dates['date']; |
||
| 181 | $startTime = $dates['start_time']; |
||
| 182 | $endTime = $dates['end_time']; |
||
| 183 | } |
||
| 184 | |||
| 185 | $js .= "<script> |
||
| 186 | $(function() { |
||
| 187 | var txtDate = $('#$id'), |
||
| 188 | inputGroup = txtDate.parents('.input-group'), |
||
| 189 | txtDateAlt = $('#{$id}_alt'), |
||
| 190 | txtDateAltText = $('#{$id}_alt_text'); |
||
| 191 | |||
| 192 | txtDate |
||
| 193 | .hide() |
||
| 194 | .datepicker({ |
||
| 195 | defaultDate: '".$defaultDate."', |
||
| 196 | dateFormat: 'yy-mm-dd', |
||
| 197 | altField: '#{$id}_alt', |
||
| 198 | altFormat: \"".get_lang('DateFormatLongNoDayJS')."\", |
||
| 199 | showOn: 'both', |
||
| 200 | buttonImage: '".Display::return_icon('attendance.png', null, [], ICON_SIZE_TINY, true, true)."', |
||
| 201 | buttonImageOnly: true, |
||
| 202 | buttonText: '".get_lang('SelectDate')."', |
||
| 203 | changeMonth: true, |
||
| 204 | changeYear: true, |
||
| 205 | yearRange: 'c-60y:c+5y' |
||
| 206 | }) |
||
| 207 | .on('change', function (e) { |
||
| 208 | txtDateAltText.text(txtDateAlt.val()); |
||
| 209 | }); |
||
| 210 | |||
| 211 | txtDateAltText.on('click', function () { |
||
| 212 | txtDate.datepicker('show'); |
||
| 213 | }); |
||
| 214 | |||
| 215 | inputGroup |
||
| 216 | .find('button') |
||
| 217 | .on('click', function (e) { |
||
| 218 | e.preventDefault(); |
||
| 219 | $('#$id, #{$id}_alt').val(''); |
||
| 220 | $('#{$id}_alt_text').html(''); |
||
| 221 | }); |
||
| 222 | |||
| 223 | $('#".$id."_time_range .time').timepicker({ |
||
| 224 | 'showDuration': true, |
||
| 225 | 'timeFormat': 'H:i:s', |
||
| 226 | 'scrollDefault': 'now', |
||
| 227 | }); |
||
| 228 | |||
| 229 | $('#".$id."_time_range_start').timepicker('setTime', new Date('".$startTime."')); |
||
| 230 | $('#".$id."_time_range_end').timepicker('setTime', new Date('".$endTime."')); |
||
| 231 | |||
| 232 | var timeOnlyExampleEl = document.getElementById('".$id."_time_range'); |
||
| 233 | var timeOnlyDatepair = new Datepair(timeOnlyExampleEl); |
||
| 234 | }); |
||
| 235 | </script>"; |
||
| 236 | |||
| 237 | return $js; |
||
| 238 | } |
||
| 240 |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.