Completed
Push — development ( 65f470...5cb407 )
by timmeyy23
03:34
created

OnlineBankTransfer   F

Complexity

Conditions 13
Paths 648

Size

Total Lines 153

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 13
nc 648
nop 5
dl 0
loc 153
rs 2.4575
c 1
b 0
f 1

12 Functions

Rating   Name   Duplication   Size   Complexity  
A onlinebanktransfer.js ➔ ... ➔ sofortPaymentMethodContainer.click 0 12 4
A onlinebanktransfer.js ➔ ... ➔ enableAccountNumber 0 6 2
A onlinebanktransfer.js ➔ ... ➔ enableBankCode 0 6 2
C onlinebanktransfer.js ➔ ... ➔ disableAll 0 26 11
A onlinebanktransfer.js ➔ ... ➔ pffPaymentMethodContainer.click 0 3 1
A onlinebanktransfer.js ➔ ... ➔ enableSepaBic 0 7 2
A onlinebanktransfer.js ➔ ... ➔ giropayPaymentMethodContainer.click 0 5 1
A onlinebanktransfer.js ➔ ... ➔ enableBankGroupAt 0 6 2
A onlinebanktransfer.js ➔ ... ➔ enableBankGroupNl 0 6 2
A onlinebanktransfer.js ➔ ... ➔ epsPaymentMethodContainer.click 0 5 1
A onlinebanktransfer.js ➔ ... ➔ idlPaymentMethodContainer.click 0 4 1
A onlinebanktransfer.js ➔ ... ➔ enableSepaIban 0 7 2

How to fix   Long Method    Complexity   

Long Method

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:

Complexity

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
/**
2
 *
3
 * NOTICE OF LICENSE
4
 *
5
 * This source file is subject to the GNU General Public License (GPL 3)
6
 * that is bundled with this package in the file LICENSE.txt
7
 *
8
 * DISCLAIMER
9
 *
10
 * Do not edit or add to this file if you wish to upgrade Payone_Core to newer
11
 * versions in the future. If you wish to customize Payone_Core for your
12
 * needs please refer to http://www.payone.de for more information.
13
 *
14
 * @category        Payone
15
 * @package         js
16
 * @subpackage      payone
17
 * @copyright       Copyright (c) 2012 <[email protected]> - www.noovias.com, Copyright (c) 2017 <[email protected]> - www.e3n.de
18
 * @author          Matthias Walter <[email protected]>, Tim Rein <[email protected]>
19
 * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
20
 * @link            http://www.noovias.com, http://www.e3n.de
21
 */
22
23
/**
24
 *
25
 * @param typeCode
26
 * @param methodCode
27
 * @param element
28
 * @param country
29
 * @param currency
30
 */
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) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

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.

Loading history...
102
                disableAll();
103
                enableBankGroupAt();
104
                alert('dsfsddf');
105
            });
106
        }
107
    }
108
    if (typeCode == 'IDL') {
109
        if (idlPaymentMethodContainer) {
110
            idlPaymentMethodContainer.on("click", function (event) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

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.

Loading history...
111
                disableAll();
112
                enableBankGroupNl();
113
            });
114
        }
115
    }
116
    if (typeCode == 'GPY') {
117
        if (giropayPaymentMethodContainer) {
118
            giropayPaymentMethodContainer.on("click", function (event) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

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.

Loading history...
119
                disableAll();
120
                enableSepaIban();
121
                enableSepaBic();
122
            });
123
        }
124
    }
125
126
127
    if (typeCode == 'PFF') {
128
        if(pffPaymentMethodContainer){
129
            pffPaymentMethodContainer.on("click", function (event) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

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.

Loading history...
130
                disableAll();
131
            });
132
        }
133
    }
134
135
    if (typeCode == 'PNT') {
136
        if(sofortPaymentMethodContainer){
137
            sofortPaymentMethodContainer.on("click", function (event) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

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.

Loading history...
138
                disableAll();
139
                if (sofortueberweisungShowIban.value == 1) {
140
                    enableSepaIban();
141
                    enableSepaBic();
142
                }
143
144
                if (country == 'CH' && currency == 'CHF') {
145
                    enableAccountNumber();
146
                    enableBankCode();
147
                }
148
            });
149
        }
150
    }
151
152
    if (typeCode == 'PFC' || typeCode == 'P24') {
153
        disableAll();
154
    }
155
156
    function disableAll() {
157
        if (accountNumberWrap && accountNumberInput) {
158
            accountNumberWrap.hide();
159
            accountNumberInput.setAttribute("disabled", "disabled");
160
        }
161
162
        if (bankCodeWrap && bankCodeInput) {
163
            bankCodeWrap.hide();
164
            bankCodeInput.setAttribute("disabled", "disabled");
165
        }
166
167
        if (sepaIbanWrap && sepaIbanInput) {
168
            sepaIbanWrap.hide();
169
            sepaIbanInput.setAttribute("disabled", "disabled");
170
        }
171
172
        if (sepaBicWrap && sepaBicInput) {
173
            sepaBicWrap.hide();
174
            sepaBicInput.setAttribute("disabled", "disabled");
175
        }
176
177
        if (bankGroupWrapNl && bankGroupSelectNl) {
178
            bankGroupWrapNl.hide();
179
            bankGroupSelectNl.setAttribute("disabled", "disabled");
180
        }
181
    }
182
183
}
184
185
function copyOnlineBankTransferSepaIban(code) {
186
    var input_sepa_iban_xxx_el = $(code + '_sepa_iban_xxx');
187
    var input_sepa_iban_el = $(code + '_sepa_iban');
188
    input_sepa_iban_el.value = input_sepa_iban_xxx_el.value;
189
}
190