Passed
Pull Request — master (#16)
by
unknown
15:25
created

paylater.js ➔ define   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 42
rs 9.304
c 4
b 0
f 0
cc 1
nc 1
nop 11

5 Functions

Rating   Name   Duplication   Size   Complexity  
A paylater.js ➔ ... ➔ Component.extend.placeOrder 0 10 1
A paylater.js ➔ ... ➔ Component.extend.getSubtitle 0 3 1
A paylater.js ➔ ... ➔ Component.extend.selectPaymentMethod 0 5 1
A paylater.js ➔ ... ➔ Component.extend.getDisplayMode 0 3 1
A paylater.js ➔ ... ➔ Component.extend.getTitle 0 3 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
define(
2
    [
3
        'jquery',
4
        'Magento_Checkout/js/view/payment/default',
5
        'mage/url',
6
        'Magento_Customer/js/customer-data',
7
        'Magento_Checkout/js/model/error-processor',
8
        'Magento_Checkout/js/model/full-screen-loader',
9
        'Magento_Checkout/js/model/quote',
10
        'Magento_Checkout/js/action/select-payment-method',
11
        'Magento_Checkout/js/checkout-data',
12
        'Magento_Checkout/js/model/totals',
13
        'Magento_Catalog/js/price-utils'
14
    ],
15
    function ($, Component, url, customerData, errorProcessor, fullScreenLoader, quote, selectPaymentMethodAction, checkoutData, totals, priceUtils) {
0 ignored issues
show
Unused Code introduced by
The parameter priceUtils 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...
Unused Code introduced by
The parameter totals 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...
16
        'use strict';
17
18
        window.checkoutConfig.payment.paylater.guestEmail = quote.guestEmail;
19
20
        return Component.extend({
21
                defaults: {
22
                    template: 'DigitalOrigin_Pmt/payment/checkout-form'
23
                },
24
25
                redirectAfterPlaceOrder: false,
26
27
                getTitle: function () {
28
                    return window.checkoutConfig.payment.paylater.title
29
                },
30
31
                getSubtitle: function () {
32
                    return window.checkoutConfig.payment.paylater.subtitle
33
                },
34
35
                getDisplayMode: function () {
36
                    return window.checkoutConfig.payment.paylater.displayMode
37
                },
38
39
                selectPaymentMethod: function() {
40
                    selectPaymentMethodAction(this.getData());
41
                    checkoutData.setSelectedPaymentMethod(this.item.method);
42
                    return true;
43
                },
44
45
                placeOrder: function () {
46
                    var paymentUrl = url.build('paylater/Payment');
47
                    $.post(paymentUrl, { email: window.checkoutConfig.payment.paylater.guestEmail }, 'json')
48
                        .done(function (response) {
49
                            window.location.replace(response);
50
                        })
51
                        .fail(function (response) {
52
                            window.location.replace(response);
53
                        })
54
                },
55
            });
56
    }
57
);
58