Completed
Push — master ( 95df18...b22833 )
by Florian
12:05
created

js/payone/core/onlinebanktransfer.js   B

Complexity

Total Complexity 45
Complexity/F 3.21

Size

Lines of Code 158
Function Count 14

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 0
c 2
b 0
f 1
nc 1
dl 0
loc 158
rs 8.3673
wmc 45
mnd 3
bc 38
fnc 14
bpm 2.7142
cpm 3.2142
noi 5

1 Function

Rating   Name   Duplication   Size   Complexity  
A onlinebanktransfer.js ➔ copyOnlineBankTransferSepaIban 0 5 1

How to fix   Complexity   

Complexity

Complex classes like js/payone/core/onlinebanktransfer.js 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
            });
105
        }
106
    }
107
    if (typeCode == 'IDL') {
108
        if (idlPaymentMethodContainer) {
109
            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...
110
                disableAll();
111
                enableBankGroupNl();
112
            });
113
        }
114
    }
115
    if (typeCode == 'GPY') {
116
        if (giropayPaymentMethodContainer) {
117
            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...
118
                disableAll();
119
                enableSepaIban();
120
                enableSepaBic();
121
            });
122
        }
123
    }
124
125
126
    if (typeCode == 'PFF') {
127
        if(pffPaymentMethodContainer){
128
            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...
129
                disableAll();
130
            });
131
        }
132
    }
133
134
    if (typeCode == 'PNT') {
135
        if(sofortPaymentMethodContainer){
136
            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...
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
184
function copyOnlineBankTransferSepaIban(code) {
185
    var input_sepa_iban_xxx_el = $(code + '_sepa_iban_xxx');
186
    var input_sepa_iban_el = $(code + '_sepa_iban');
187
    input_sepa_iban_el.value = input_sepa_iban_xxx_el.value;
188
}
189