Completed
Push — development ( ba0685...48f256 )
by Florian
10:37
created

js/payone/core/onlinebanktransfer.js   B

Complexity

Total Complexity 40
Complexity/F 2.86

Size

Lines of Code 140
Function Count 14

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 40
dl 0
loc 140
c 0
b 0
f 0
cc 0
nc 1
rs 8.2608
mnd 2
bc 33
fnc 14
bpm 2.3571
cpm 2.8571
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
    function enableBankGroupNl() {
48
        if (bankGroupWrapNl) {
49
            bankGroupWrapNl.show();
50
            bankGroupSelectNl.removeAttribute("disabled");
51
        }
52
    }
53
54
    function enableBankGroupAt() {
55
        if (bankGroupWrapAt) {
56
            bankGroupWrapAt.show();
57
            bankGroupSelectAt.removeAttribute("disabled");
58
        }
59
    }
60
61
    function enableAccountNumber() {
62
        if (accountNumberWrap) {
63
            accountNumberWrap.show();
64
            accountNumberInput.removeAttribute("disabled");
65
        }
66
    }
67
68
    function enableBankCode() {
69
        if (bankCodeWrap) {
70
            bankCodeWrap.show();
71
            bankCodeInput.removeAttribute("disabled");
72
        }
73
    }
74
75
    function enableSepaIban() {
76
77
        if (sepaIbanWrap) {
78
            sepaIbanWrap.show();
79
            sepaIbanInput.removeAttribute("disabled");
80
        }
81
    }
82
83
    function enableSepaBic() {
84
85
        if (sepaBicWrap) {
86
            sepaBicWrap.show();
87
            sepaBicInput.removeAttribute("disabled");
88
        }
89
    }
90
91
    if (typeCode == 'EPS') {
92
        $("dt_method_payone_online_bank_transfer_eps").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...
93
            disableAll();
94
            enableBankGroupAt();
95
96
        });
97
    }
98
    if (typeCode == 'IDL') {
99
        $("dt_method_payone_online_bank_transfer_idl").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...
100
            disableAll();
101
            enableBankGroupNl();
102
        });
103
    }
104
    if (typeCode == 'GPY') {
105
        $("dt_method_payone_online_bank_transfer_giropay").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...
106
            disableAll();
107
            enableSepaIban();
108
            enableSepaBic();
109
        });
110
    }
111
112
    if (typeCode == 'PFF') {
113
        $("dt_method_payone_online_bank_transfer_pff").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...
114
            disableAll();
115
        });
116
    }
117
118
    if (typeCode == 'PNT') {
119
        $("dt_method_payone_online_bank_transfer_sofortueberweisung").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...
120
            disableAll();
121
            if (sofortueberweisungShowIban.value == 1) {
122
                enableSepaIban();
123
                enableSepaBic();
124
            }
125
126
            if (country == 'CH' && currency == 'CHF') {
127
                enableAccountNumber();
128
                enableBankCode();
129
            }
130
        });
131
    }
132
133
    if (typeCode == 'PFC' || typeCode == 'P24') {
134
        disableAll();
135
    }
136
137
    function disableAll() {
138
        if (accountNumberWrap && accountNumberInput) {
139
            accountNumberWrap.hide();
140
            accountNumberInput.setAttribute("disabled", "disabled");
141
        }
142
143
        if (bankCodeWrap && bankCodeInput) {
144
            bankCodeWrap.hide();
145
            bankCodeInput.setAttribute("disabled", "disabled");
146
        }
147
148
        if (sepaIbanWrap && sepaIbanInput) {
149
            sepaIbanWrap.hide();
150
            sepaIbanInput.setAttribute("disabled", "disabled");
151
        }
152
153
        if (sepaBicWrap && sepaBicInput) {
154
            sepaBicWrap.hide();
155
            sepaBicInput.setAttribute("disabled", "disabled");
156
        }
157
158
        if (bankGroupWrapNl && bankGroupSelectNl) {
159
            bankGroupWrapNl.hide();
160
            bankGroupSelectNl.setAttribute("disabled", "disabled");
161
        }
162
    }
163
164
}
165
166
function copyOnlineBankTransferSepaIban(code) {
167
    var input_sepa_iban_xxx_el = $(code + '_sepa_iban_xxx');
168
    var input_sepa_iban_el = $(code + '_sepa_iban');
169
    input_sepa_iban_el.value = input_sepa_iban_xxx_el.value;
170
}
171