Conditions | 2 |
Paths | 2 |
Total Lines | 77 |
Code Lines | 55 |
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 | var handleTimePeriodEndTodayCheckboxChange = function () { |
||
17 | $('.sylius-autocomplete').each(function(idx, el) { |
||
18 | var element = $(el); |
||
19 | var criteriaName = element |
||
20 | .data('criteria-name'); |
||
21 | var choiceName = element |
||
22 | .data('choice-name'); |
||
23 | var choiceValue = element |
||
24 | .data('choice-value'); |
||
25 | var autocompleteValue = element |
||
26 | .find('input.autocomplete') |
||
27 | .val(); |
||
28 | var loadForEditUrl = element |
||
29 | .data('load-edit-url'); |
||
30 | |||
31 | element |
||
32 | .dropdown({ |
||
33 | delay: { |
||
34 | search: 250 |
||
35 | }, |
||
36 | minCharacters: 3, |
||
37 | forceSelection: false, |
||
38 | apiSettings: { |
||
39 | dataType: 'JSON', |
||
40 | cache: false, |
||
41 | beforeSend: function beforeSend(settings) { |
||
42 | /* eslint-disable-next-line no-param-reassign */ |
||
43 | settings.data[criteriaName] = settings.urlData.query; |
||
44 | |||
45 | return settings; |
||
46 | }, |
||
47 | onResponse: function onResponse(response) { |
||
48 | return { |
||
49 | success: true, |
||
50 | results: response.map(function (item) { |
||
51 | return { |
||
52 | name: item[choiceName], |
||
53 | value: item[choiceValue] |
||
54 | }; |
||
55 | }) |
||
56 | }; |
||
57 | } |
||
58 | } |
||
59 | }); |
||
60 | |||
61 | if (autocompleteValue.split(',') |
||
62 | .filter(String).length > 0) { |
||
63 | var menuElement = element |
||
64 | .find('div.menu'); |
||
65 | |||
66 | menuElement.api({ |
||
67 | on: 'now', |
||
68 | method: 'GET', |
||
69 | url: loadForEditUrl, |
||
70 | beforeSend: function beforeSend(settings) { |
||
71 | /* eslint-disable-next-line no-param-reassign */ |
||
72 | settings.data[choiceValue] = autocompleteValue.split(',') |
||
73 | .filter(String); |
||
74 | |||
75 | return settings; |
||
76 | }, |
||
77 | onSuccess: function onSuccess(response) { |
||
78 | response.forEach(function (item) { |
||
79 | menuElement.append($('<div class="item" data-value="' + item[choiceValue] + '">' + item[choiceName] + '</div>')); |
||
80 | }); |
||
81 | } |
||
82 | }); |
||
83 | } |
||
84 | |||
85 | window.setTimeout(function () { |
||
86 | element |
||
87 | .dropdown('set selected', element |
||
88 | .find('input.autocomplete') |
||
89 | .val() |
||
90 | .split(',') |
||
91 | .filter(String)); |
||
92 | }, 5000); |
||
93 | }); |
||
94 | }; |
||
127 | })( jQuery ); |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.