Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 29 |
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 |
||
37 | protected function setControlHtml(string $name) |
||
38 | { |
||
39 | $divGroup = Html::el('div', ['class' => "input-group dateTimeRangeDiv"]); |
||
40 | $divGroupAddonClock = Html::el('div', ['class' => "input-group-addon", 'id' => $this->uniqueId . 'Focus']); |
||
41 | $divGroupAddonTimes = Html::el('div', ['class' => "input-group-addon", 'id' => $this->uniqueId . 'Clear']); |
||
42 | $iClock = Html::el('i', ['class' => "fa fa-clock-o"]); |
||
43 | $iTimes = Html::el('i', ['class' => "fa fa-times"]); |
||
44 | $input = $this->input = Html::el('input', [ |
||
45 | 'type' => 'text', |
||
46 | 'name' => $name, |
||
47 | 'id' => $this->uniqueId, |
||
48 | 'class' => 'form-control pull-right active', |
||
49 | 'aria-label' => _('Time from - to') |
||
50 | ]); |
||
51 | |||
52 | // http://www.daterangepicker.com/ |
||
53 | $scriptText = 'document.addEventListener(\'DOMContentLoaded\', function() { |
||
54 | moment.locale(\'cs\'); |
||
55 | $("#' . $this->uniqueId . '").daterangepicker({ |
||
56 | autoUpdateInput: false, |
||
57 | timePicker: true, |
||
58 | timePicker24Hour: true, |
||
59 | timePickerIncrement: 15, |
||
60 | locale: { |
||
61 | "format": "DD.MM.YYYY H:mm", // TODO because processing until it will be defined internationalization |
||
62 | customRangeLabel: "' . t('Own range') . '", |
||
|
|||
63 | applyLabel: "' . t('Use') . '", |
||
64 | cancelLabel: "' . t('Cancel') . '", |
||
65 | }, |
||
66 | }, |
||
67 | function (start, end) { |
||
68 | $(\'#' . $this->uniqueId . '\') |
||
69 | .val(start.format(\'DD.MM.YYYY H:mm\') + \' - \' + end.format(\'DD.MM.YYYY H:mm\')) |
||
70 | .trigger(\'change\'); |
||
71 | } |
||
72 | ); |
||
73 | $(\'.dateTimeRangeDiv input\').change(function() { |
||
74 | $(this).parents(\'form\').submit(); |
||
75 | }); |
||
76 | $(\'#' . $this->uniqueId . 'Focus' . '\').click(function(){ |
||
77 | $(' . $this->uniqueId . ').focus(); |
||
78 | }); |
||
79 | $(\'#' . $this->uniqueId . 'Clear' . '\').click(function(){ |
||
80 | $(' . $this->uniqueId . ').val(\'\'); |
||
81 | $(this).parents(\'form\').submit(); |
||
82 | }); |
||
83 | }, false);'; |
||
84 | $script = Html::el('script')->add($scriptText); |
||
85 | |||
86 | $divGroupAddonClock->add($iClock); |
||
87 | $divGroupAddonTimes->add($iTimes); |
||
88 | $divGroup->add($divGroupAddonClock); |
||
89 | $divGroup->add($divGroupAddonTimes); |
||
90 | $divGroup->add($input); |
||
91 | $divGroup->add($script); |
||
92 | $this->control = $divGroup; |
||
93 | } |
||
138 |