Conditions | 13 |
Paths | 648 |
Total Lines | 152 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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:
Complex classes like onlinebanktransfer.js ➔ payoneSwitchOnlineBankTransfer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | /** |
||
31 | function payoneSwitchOnlineBankTransfer(typeCode, methodCode, element, country, currency) { |
||
32 | |||
33 | var accountNumberWrap = $('account_number_wrap'); |
||
34 | var bankCodeWrap = $('bank_code_wrap'); |
||
35 | var sepaIbanWrap = $('sepa_iban_wrap'); |
||
36 | var sepaBicWrap = $('sepa_bic_wrap'); |
||
37 | var bankGroupWrapAt = $('bank_group_wrap_at'); |
||
38 | var bankGroupWrapNl = $('bank_group_wrap_nl'); |
||
39 | var accountNumberInput = $(methodCode + '_account_number'); |
||
40 | var bankCodeInput = $(methodCode + '_bank_code'); |
||
41 | var sepaIbanInput = $(methodCode + '_sepa_iban'); |
||
42 | var sepaBicInput = $(methodCode + '_sepa_bic'); |
||
43 | var bankGroupSelectAt = $(methodCode + '_bank_group_at'); |
||
44 | var bankGroupSelectNl = $(methodCode + '_bank_group_nl'); |
||
45 | var sofortueberweisungShowIban = $(methodCode + '_pnt_show_iban'); |
||
46 | // |
||
47 | var epsPaymentMethodContainer = $("dt_method_payone_online_bank_transfer_eps") || $('p_method_payone_online_bank_transfer_eps'); |
||
48 | var idlPaymentMethodContainer = $("dt_method_payone_online_bank_transfer_idl") || $('p_method_payone_online_bank_transfer_idl'); |
||
49 | var giropayPaymentMethodContainer = $("dt_method_payone_online_bank_transfer_giropay") || $('p_method_payone_online_bank_transfer_giropay'); |
||
50 | var pffPaymentMethodContainer = $("dt_method_payone_online_bank_transfer_pff") || $('p_method_payone_online_bank_transfer_pff'); |
||
51 | var sofortPaymentMethodContainer = $("dt_method_payone_online_bank_transfer_sofortueberweisung") || $('p_method_payone_online_bank_transfer_sofortueberweisung'); |
||
52 | |||
53 | |||
54 | |||
55 | function enableBankGroupNl() { |
||
56 | if (bankGroupWrapNl) { |
||
57 | bankGroupWrapNl.show(); |
||
58 | bankGroupSelectNl.removeAttribute("disabled"); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | function enableBankGroupAt() { |
||
63 | if (bankGroupWrapAt) { |
||
64 | bankGroupWrapAt.show(); |
||
65 | bankGroupSelectAt.removeAttribute("disabled"); |
||
66 | } |
||
67 | } |
||
68 | |||
69 | function enableAccountNumber() { |
||
70 | if (accountNumberWrap) { |
||
71 | accountNumberWrap.show(); |
||
72 | accountNumberInput.removeAttribute("disabled"); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | function enableBankCode() { |
||
77 | if (bankCodeWrap) { |
||
78 | bankCodeWrap.show(); |
||
79 | bankCodeInput.removeAttribute("disabled"); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | function enableSepaIban() { |
||
84 | |||
85 | if (sepaIbanWrap) { |
||
86 | sepaIbanWrap.show(); |
||
87 | sepaIbanInput.removeAttribute("disabled"); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | function enableSepaBic() { |
||
92 | |||
93 | if (sepaBicWrap) { |
||
94 | sepaBicWrap.show(); |
||
95 | sepaBicInput.removeAttribute("disabled"); |
||
96 | } |
||
97 | } |
||
98 | |||
99 | if (typeCode == 'EPS') { |
||
100 | if(epsPaymentMethodContainer) { |
||
101 | epsPaymentMethodContainer.on("click", function (event) { |
||
|
|||
102 | disableAll(); |
||
103 | enableBankGroupAt(); |
||
104 | }); |
||
105 | } |
||
106 | } |
||
107 | if (typeCode == 'IDL') { |
||
108 | if (idlPaymentMethodContainer) { |
||
109 | idlPaymentMethodContainer.on("click", function (event) { |
||
110 | disableAll(); |
||
111 | enableBankGroupNl(); |
||
112 | }); |
||
113 | } |
||
114 | } |
||
115 | if (typeCode == 'GPY') { |
||
116 | if (giropayPaymentMethodContainer) { |
||
117 | giropayPaymentMethodContainer.on("click", function (event) { |
||
118 | disableAll(); |
||
119 | enableSepaIban(); |
||
120 | enableSepaBic(); |
||
121 | }); |
||
122 | } |
||
123 | } |
||
124 | |||
125 | |||
126 | if (typeCode == 'PFF') { |
||
127 | if(pffPaymentMethodContainer){ |
||
128 | pffPaymentMethodContainer.on("click", function (event) { |
||
129 | disableAll(); |
||
130 | }); |
||
131 | } |
||
132 | } |
||
133 | |||
134 | if (typeCode == 'PNT') { |
||
135 | if(sofortPaymentMethodContainer){ |
||
136 | sofortPaymentMethodContainer.on("click", function (event) { |
||
137 | disableAll(); |
||
138 | if (sofortueberweisungShowIban.value == 1) { |
||
139 | enableSepaIban(); |
||
140 | enableSepaBic(); |
||
141 | } |
||
142 | |||
143 | if (country == 'CH' && currency == 'CHF') { |
||
144 | enableAccountNumber(); |
||
145 | enableBankCode(); |
||
146 | } |
||
147 | }); |
||
148 | } |
||
149 | } |
||
150 | |||
151 | if (typeCode == 'PFC' || typeCode == 'P24') { |
||
152 | disableAll(); |
||
153 | } |
||
154 | |||
155 | function disableAll() { |
||
156 | if (accountNumberWrap && accountNumberInput) { |
||
157 | accountNumberWrap.hide(); |
||
158 | accountNumberInput.setAttribute("disabled", "disabled"); |
||
159 | } |
||
160 | |||
161 | if (bankCodeWrap && bankCodeInput) { |
||
162 | bankCodeWrap.hide(); |
||
163 | bankCodeInput.setAttribute("disabled", "disabled"); |
||
164 | } |
||
165 | |||
166 | if (sepaIbanWrap && sepaIbanInput) { |
||
167 | sepaIbanWrap.hide(); |
||
168 | sepaIbanInput.setAttribute("disabled", "disabled"); |
||
169 | } |
||
170 | |||
171 | if (sepaBicWrap && sepaBicInput) { |
||
172 | sepaBicWrap.hide(); |
||
173 | sepaBicInput.setAttribute("disabled", "disabled"); |
||
174 | } |
||
175 | |||
176 | if (bankGroupWrapNl && bankGroupSelectNl) { |
||
177 | bankGroupWrapNl.hide(); |
||
178 | bankGroupSelectNl.setAttribute("disabled", "disabled"); |
||
179 | } |
||
180 | } |
||
181 | |||
182 | } |
||
183 | |||
189 |
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.