Conditions | 1 |
Paths | 3 |
Total Lines | 85 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | define(function(require) { |
||
2 | 'use strict'; |
||
3 | |||
4 | var ButtonComponent = require('oroworkflow/js/app/components/button-component'); |
||
5 | var StandardConfirmation = require('oroui/js/standart-confirmation'); |
||
6 | var __ = require('orotranslation/js/translator'); |
||
7 | var ShoppingListCreateOrderButtonComponent; |
||
8 | |||
9 | ShoppingListCreateOrderButtonComponent = ButtonComponent.extend({ |
||
10 | hasEmptyMatrix: null, |
||
11 | |||
12 | shoppingListCollection: null, |
||
13 | |||
14 | lineItemsCount: null, |
||
15 | |||
16 | /** |
||
17 | * @type {Object} |
||
18 | */ |
||
19 | messages: { |
||
20 | content: __('oro.shoppinglist.create_order_confirmation.message'), |
||
21 | title: __('oro.shoppinglist.create_order_confirmation.title'), |
||
22 | okText: __('oro.shoppinglist.create_order_confirmation.accept_button_title'), |
||
23 | cancelText: __('oro.shoppinglist.create_order_confirmation.cancel_button_title') |
||
24 | }, |
||
25 | |||
26 | listen: { |
||
27 | 'line-items-init mediator': '_onLineItemsInit' |
||
28 | }, |
||
29 | |||
30 | /** |
||
31 | * @inheritDoc |
||
32 | */ |
||
33 | initialize: function(options) { |
||
34 | this.hasEmptyMatrix = options.hasEmptyMatrix; |
||
35 | return ShoppingListCreateOrderButtonComponent.__super__.initialize.apply(this, arguments); |
||
36 | }, |
||
37 | |||
38 | /** |
||
39 | * Listen line items init process |
||
40 | * |
||
41 | * @param {Array} lineItems |
||
42 | * @private |
||
43 | */ |
||
44 | _onLineItemsInit: function(lineItems) { |
||
45 | this.lineItemsCount = lineItems.filter(function(lineItem) { |
||
46 | return lineItem.$el.attr('class').indexOf('--configurable') === -1; |
||
47 | }).length; |
||
48 | }, |
||
49 | |||
50 | /** |
||
51 | * @inheritDoc |
||
52 | */ |
||
53 | _onClickButtonExecutor: function(clickedButton) { |
||
|
|||
54 | this.showConfirmation(ShoppingListCreateOrderButtonComponent.__super__ |
||
55 | ._onClickButtonExecutor.bind(this, arguments)); |
||
56 | }, |
||
57 | |||
58 | /** |
||
59 | * @inheritDoc |
||
60 | */ |
||
61 | _onClickButtonRedirect: function(clickedButton) { |
||
62 | this.showConfirmation(ShoppingListCreateOrderButtonComponent.__super__ |
||
63 | ._onClickButtonRedirect |
||
64 | .bind(this, arguments)); |
||
65 | }, |
||
66 | |||
67 | showConfirmation: function(callback) { |
||
68 | if ( |
||
69 | (this.hasEmptyMatrix && this.lineItemsCount === 0) || // empty matrix only |
||
70 | (!this.hasEmptyMatrix) // not empty matrix or it doesn't exist in SL |
||
71 | ) { |
||
72 | callback(); |
||
73 | return; |
||
74 | } |
||
75 | |||
76 | var confirmModal = new StandardConfirmation(this.messages); |
||
77 | confirmModal |
||
78 | .off('ok') |
||
79 | .on('ok') |
||
80 | .open(callback); |
||
81 | } |
||
82 | }); |
||
83 | |||
84 | return ShoppingListCreateOrderButtonComponent; |
||
85 | }); |
||
86 |
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.