| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 61 | private function getElementJS() |
||
| 62 | { |
||
| 63 | $js = null; |
||
| 64 | $id = $this->getAttribute('id'); |
||
| 65 | |||
| 66 | $js .= "<script> |
||
| 67 | $(function() { |
||
| 68 | var txtDate = $('#$id'), |
||
| 69 | inputGroup = txtDate.parents('.input-group'), |
||
| 70 | txtDateAlt = $('#{$id}_alt'), |
||
| 71 | txtDateAltText = $('#{$id}_alt_text'); |
||
| 72 | |||
| 73 | txtDate |
||
| 74 | .hide() |
||
| 75 | .datepicker({ |
||
| 76 | defaultDate: '".$this->getValue()."', |
||
| 77 | dateFormat: 'yy-mm-dd', |
||
| 78 | altField: '#{$id}_alt', |
||
| 79 | altFormat: \"".get_lang('DateFormatLongNoDayJS')."\", |
||
| 80 | showOn: 'both', |
||
| 81 | buttonImage: '".Display::return_icon('attendance.png', null, [], ICON_SIZE_TINY, true, true)."', |
||
| 82 | buttonImageOnly: true, |
||
| 83 | buttonText: '".get_lang('SelectDate')."', |
||
| 84 | changeMonth: true, |
||
| 85 | changeYear: true, |
||
| 86 | yearRange: 'c-60y:c+5y' |
||
| 87 | }) |
||
| 88 | .on('change', function (e) { |
||
| 89 | txtDateAltText.text(txtDateAlt.val()); |
||
| 90 | }); |
||
| 91 | |||
| 92 | txtDateAltText.on('click', function () { |
||
| 93 | txtDate.datepicker('show'); |
||
| 94 | }); |
||
| 95 | |||
| 96 | inputGroup |
||
| 97 | .find('button') |
||
| 98 | .on('click', function (e) { |
||
| 99 | e.preventDefault(); |
||
| 100 | |||
| 101 | $('#$id, #{$id}_alt').val(''); |
||
| 102 | $('#{$id}_alt_text').html(''); |
||
| 103 | }); |
||
| 104 | |||
| 105 | $('#".$id."_time_range .time').timepicker({ |
||
| 106 | 'showDuration': true, |
||
| 107 | 'timeFormat': 'H:i:s', |
||
| 108 | 'scrollDefault': 'now', |
||
| 109 | |||
| 110 | }); |
||
| 111 | var timeOnlyExampleEl = document.getElementById('".$id."_time_range'); |
||
| 112 | var timeOnlyDatepair = new Datepair(timeOnlyExampleEl); |
||
| 113 | |||
| 114 | }); |
||
| 115 | </script>"; |
||
| 116 | |||
| 117 | return $js; |
||
| 118 | } |
||
| 120 |