Completed
Push — master ( 213d43...639363 )
by Florian
9s
created

Component.extend.handleCreditcardPayment   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 4
nop 0
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
1
/**
2
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
3
 * it under the terms of the GNU Lesser General Public License as published by
4
 * the Free Software Foundation, either version 3 of the License, or
5
 * (at your option) any later version.
6
 *
7
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU Lesser General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU Lesser General Public License
13
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
14
 *
15
 * PHP version 5
16
 *
17
 * @category  Payone
18
 * @package   Payone_Magento2_Plugin
19
 * @author    FATCHIP GmbH <[email protected]>
20
 * @copyright 2003 - 2016 Payone GmbH
21
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
22
 * @link      http://www.payone.de
23
 */
24
define(
25
    [
26
        'Magento_Checkout/js/view/payment/default',
27
        'Payone_Core/js/action/handle-redirect',
28
        'Payone_Core/js/action/handle-debit',
29
        'Magento_Checkout/js/model/payment/additional-validators'
30
    ],
31
    function (Component, handleRedirectAction, handleDebitAction, additionalValidators) {
32
        'use strict';
33
        return Component.extend({
34
            continueToPayone: function () {
35
                if (this.validate() && additionalValidators.validate()) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.validate() && addit...alValidators.validate() is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
36
                    // update payment method information if additional data was changed
37
                    this.selectPaymentMethod();
38
                    handleRedirectAction(this.getData(), this.messageContainer);
39
                    return false;
40
                }
41
            },
42
            
43
            handleCreditcardPayment: function () {
44
                var firstValidation = additionalValidators.validate();
45
                if (!(firstValidation)) {
46
                    return false;
47
                }
48
49
                if (this.validate() && firstValidation) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.validate() && firstValidation is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
50
                    if (document.getElementById(this.getCode() + '_pseudocardpan').value != '') {
51
                        // update payment method information if additional data was changed
52
                        this.selectPaymentMethod();
53
                        handleRedirectAction(this.getData(), this.messageContainer);
54
                        return false;
55
                    } else {
56
                        this.handleCreditcardCheck();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
57
                    }
58
                }
59
            },
60
            
61
            handleDebitPayment: function () {
62
                if (this.validate() && additionalValidators.validate()) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.validate() && addit...alValidators.validate() is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
63
                    if (window.checkoutConfig.payment.payone.validateBankCode == true && window.checkoutConfig.payment.payone.bankCodeValidatedAndValid == false) {
64
                        this.handleBankaccountCheck();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
65
                    } else {
66
                        // update payment method information if additional data was changed
67
                        this.selectPaymentMethod();
68
                        handleDebitAction(this.getData(), this.messageContainer);
69
                        return false;
70
                    }
71
                }
72
            }
73
        });
74
    }
75
);
76