Test Setup Failed
Push — master ( cd1dab...2a689d )
by
unknown
03:51
created

shipping-methods-view.js ➔ define   A

Complexity

Conditions 1
Paths 4

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 4
nop 1
dl 0
loc 55
rs 9.7692
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A shipping-methods-view.js ➔ ... ➔ BaseView.extend.render 0 5 1
A shipping-methods-view.js ➔ ... ➔ BaseView.extend.initialize 0 8 1
A shipping-methods-view.js ➔ ... ➔ ShippingMethodsView 0 3 1
A shipping-methods-view.js ➔ ... ➔ BaseView.extend.updateShippingMethods 0 9 1

How to fix   Long Method   

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:

1
define(function(require) {
2
    'use strict';
3
4
    var ShippingMethodsView;
5
    var BaseView = require('oroui/js/app/views/base/view');
6
    var _ = require('underscore');
7
    var $ = require('jquery');
8
    var NumberFormatter = require('orolocale/js/formatter/number');
9
    var mediator = require('oroui/js/mediator');
10
11
    ShippingMethodsView = BaseView.extend({
12
        autoRender: true,
13
14
        options: {
15
            template: ''
16
        },
17
18
        /**
19
         * @inheritDoc
20
         */
21
        constructor: function ShippingMethodsView() {
22
            ShippingMethodsView.__super__.constructor.apply(this, arguments);
23
        },
24
25
        /**
26
         * @inheritDoc
27
         */
28
        initialize: function(options) {
29
            ShippingMethodsView.__super__.initialize.apply(this, arguments);
30
31
            this.options = _.defaults(options || {}, this.options);
32
            this.options.template = _.template(this.options.template);
33
34
            mediator.on('transition:failed', this.render.bind(this, []));
35
        },
36
37
        render: function(options) {
38
            this.updateShippingMethods(options);
39
            mediator.trigger('layout:adjustHeight');
40
            mediator.trigger('checkout:shipping-method:rendered');
41
        },
42
43
        updateShippingMethods: function(options) {
44
            var $el = $(this.options.template({
45
                methods: options || this.options.data.methods,
46
                currentShippingMethod: this.options.data.currentShippingMethod,
47
                currentShippingMethodType: this.options.data.currentShippingMethodType,
48
                formatter: NumberFormatter
49
            }));
50
            this.$el.html($el);
51
        }
52
    });
53
54
    return ShippingMethodsView;
55
});
56