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

order-taxes-component.js ➔ define   B

Complexity

Conditions 1
Paths 2

Size

Total Lines 82

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 2
nop 1
dl 0
loc 82
rs 8.7769
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A order-taxes-component.js ➔ ... ➔ BaseComponent.extend.dispose 0 9 2
A order-taxes-component.js ➔ ... ➔ BaseComponent.extend.prepareItem 0 8 1
A order-taxes-component.js ➔ ... ➔ BaseComponent.extend.appendTaxResult 0 4 1
A order-taxes-component.js ➔ ... ➔ BaseComponent.extend.initialize 0 7 1
A order-taxes-component.js ➔ ... ➔ OrderTaxesComponent 0 3 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 OrderTaxesComponent;
5
    var _ = require('underscore');
6
    var $ = require('jquery');
7
    var mediator = require('oroui/js/mediator');
8
    var BaseComponent = require('oroui/js/app/components/base/component');
9
    var TaxFormatter = require('orotax/js/formatter/tax');
10
11
    /**
12
     * @export orotax/js/app/components/order-taxes-component
13
     * @extends oroui.app.components.base.Component
14
     * @class orotax.app.components.OrderTaxesComponent
15
     */
16
    OrderTaxesComponent = BaseComponent.extend({
17
        /**
18
         * @property {Object}
19
         */
20
        options: {
21
            selectors: {
22
                totalsTemplate: '#order-taxes-totals-template',
23
                collapseSelector: '#order-taxes-totals-table'
24
            }
25
        },
26
27
        /**
28
         * @property {Object}
29
         */
30
        totalsTemplate: null,
31
32
        /**
33
         * @inheritDoc
34
         */
35
        constructor: function OrderTaxesComponent() {
36
            OrderTaxesComponent.__super__.constructor.apply(this, arguments);
37
        },
38
39
        /**
40
         * @inheritDoc
41
         */
42
        initialize: function(options) {
43
            this.options = _.defaults(options || {}, this.options);
44
45
            mediator.on('entry-point:order:trigger:totals', this.appendTaxResult, this);
46
47
            this.totalsTemplate = $(this.options.selectors.totalsTemplate).html();
48
        },
49
50
        appendTaxResult: function(totals) {
51
            var subtotals = _.extend({subtotals: {}}, totals).subtotals;
52
            _.map(_.where(subtotals, {type: 'tax'}), _.bind(this.prepareItem, this));
53
        },
54
55
        /**
56
         * @param {Object} item
57
         */
58
        prepareItem: function(item) {
59
            item.data.total = TaxFormatter.formatItem(item.data.total);
60
            item.data.shipping = TaxFormatter.formatItem(item.data.shipping);
61
            item.data.taxes = _.map(item.data.taxes, TaxFormatter.formatTax);
62
63
            item.data.in = $(this.options.selectors.collapseSelector).hasClass('in');
64
            item.template = this.totalsTemplate;
65
        },
66
67
        /**
68
         * @inheritDoc
69
         */
70
        dispose: function() {
71
            if (this.disposed) {
72
                return;
73
            }
74
75
            mediator.off('entry-point:order:trigger:totals', this.appendTaxResult, this);
76
77
            OrderTaxesComponent.__super__.dispose.call(this);
78
        }
79
    });
80
81
    return OrderTaxesComponent;
82
});
83