| 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 |
||
| 190 | private function getElementJS() |
||
| 191 | { |
||
| 192 | $js = null; |
||
| 193 | $id = $this->getAttribute('id'); |
||
| 194 | |||
| 195 | $dateRange = $this->getValue(); |
||
| 196 | |||
| 197 | $defaultDate = ''; |
||
| 198 | $startTime = ''; |
||
| 199 | $endTime = ''; |
||
| 200 | if (!empty($dateRange)) { |
||
| 201 | $dates = $this->parseDateRange($dateRange); |
||
| 202 | $defaultDate = $dates['date']; |
||
| 203 | $startTime = $dates['start_time']; |
||
| 204 | $endTime = $dates['end_time']; |
||
| 205 | } |
||
| 206 | |||
| 207 | $js .= "<script> |
||
| 208 | $(function() { |
||
| 209 | var txtDate = $('#$id'), |
||
| 210 | inputGroup = txtDate.parents('.input-group'), |
||
| 211 | txtDateAlt = $('#{$id}_alt'), |
||
| 212 | txtDateAltText = $('#{$id}_alt_text'); |
||
| 213 | |||
| 214 | txtDate |
||
| 215 | .hide() |
||
| 216 | .datepicker({ |
||
| 217 | defaultDate: '".$defaultDate."', |
||
| 218 | dateFormat: 'yy-mm-dd', |
||
| 219 | altField: '#{$id}_alt', |
||
| 220 | altFormat: \"".get_lang('DateFormatLongNoDayJS')."\", |
||
| 221 | showOn: 'both', |
||
| 222 | buttonImage: '".Display::return_icon('attendance.png', null, [], ICON_SIZE_TINY, true, true)."', |
||
| 223 | buttonImageOnly: true, |
||
| 224 | buttonText: '".get_lang('SelectDate')."', |
||
| 225 | changeMonth: true, |
||
| 226 | changeYear: true, |
||
| 227 | yearRange: 'c-60y:c+5y' |
||
| 228 | }) |
||
| 229 | .on('change', function (e) { |
||
| 230 | txtDateAltText.text(txtDateAlt.val()); |
||
| 231 | }); |
||
| 232 | |||
| 233 | txtDateAltText.on('click', function () { |
||
| 234 | txtDate.datepicker('show'); |
||
| 235 | }); |
||
| 236 | |||
| 237 | inputGroup |
||
| 238 | .find('button') |
||
| 239 | .on('click', function (e) { |
||
| 240 | e.preventDefault(); |
||
| 241 | $('#$id, #{$id}_alt').val(''); |
||
| 242 | $('#{$id}_alt_text').html(''); |
||
| 243 | }); |
||
| 244 | |||
| 245 | $('#".$id."_time_range .time').timepicker({ |
||
| 246 | 'showDuration': true, |
||
| 247 | 'timeFormat': 'H:i:s', |
||
| 248 | 'scrollDefault': 'now', |
||
| 249 | }); |
||
| 250 | |||
| 251 | $('#".$id."_time_range_start').timepicker('setTime', new Date('".$startTime."')); |
||
| 252 | $('#".$id."_time_range_end').timepicker('setTime', new Date('".$endTime."')); |
||
| 253 | |||
| 254 | var timeOnlyExampleEl = document.getElementById('".$id."_time_range'); |
||
| 255 | var timeOnlyDatepair = new Datepair(timeOnlyExampleEl); |
||
| 256 | }); |
||
| 257 | </script>"; |
||
| 258 | |||
| 259 | return $js; |
||
| 260 | } |
||
| 262 |
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.