InvoiceDataGrid::configureColumns()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 105
Code Lines 70

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 105
rs 8.2857
c 0
b 0
f 0
cc 1
eloc 70
nc 1
nop 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
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\InvoiceBundle\DataGrid;
14
15
use WellCommerce\Bundle\CoreBundle\DataGrid\AbstractDataGrid;
16
use WellCommerce\Component\DataGrid\Column\Column;
17
use WellCommerce\Component\DataGrid\Column\ColumnCollection;
18
use WellCommerce\Component\DataGrid\Column\Options\Appearance;
19
use WellCommerce\Component\DataGrid\Column\Options\Filter;
20
use WellCommerce\Component\DataGrid\Column\Options\Sorting;
21
use WellCommerce\Component\DataGrid\Configuration\EventHandler\ClickRowEventHandler;
22
use WellCommerce\Component\DataGrid\Configuration\EventHandler\DeleteGroupEventHandler;
23
use WellCommerce\Component\DataGrid\Configuration\EventHandler\DeleteRowEventHandler;
24
use WellCommerce\Component\DataGrid\Configuration\EventHandler\LoadEventHandler;
25
use WellCommerce\Component\DataGrid\DataGridInterface;
26
use WellCommerce\Component\DataGrid\Options\OptionsInterface;
27
28
/**
29
 * Class InvoiceDataGrid
30
 *
31
 * @author  Adam Piotrowski <[email protected]>
32
 */
33
class InvoiceDataGrid extends AbstractDataGrid
34
{
35
    public function configureColumns(ColumnCollection $collection)
36
    {
37
        $collection->add(new Column([
38
            'id'         => 'id',
39
            'caption'    => 'invoice.label.id',
40
            'appearance' => new Appearance([
41
                'width'   => 40,
42
                'visible' => false,
43
                'align'   => Appearance::ALIGN_CENTER,
44
            ]),
45
            'filter'     => new Filter([
46
                'type' => Filter::FILTER_BETWEEN,
47
            ]),
48
        ]));
49
        
50
        $collection->add(new Column([
51
            'id'         => 'number',
52
            'caption'    => 'invoice.label.number',
53
            'filter'     => new Filter([
54
                'type' => Filter::FILTER_INPUT,
55
            ]),
56
            'sorting'    => new Sorting([
57
                'default_order' => Sorting::SORT_DIR_DESC,
58
            ]),
59
            'appearance' => new Appearance([
60
                'width' => 40,
61
                'align' => Appearance::ALIGN_CENTER,
62
            ]),
63
        ]));
64
    
65
        $collection->add(new Column([
66
            'id'         => 'orderNumber',
67
            'caption'    => 'invoice.label.order_number',
68
            'filter'     => new Filter([
69
                'type' => Filter::FILTER_INPUT,
70
            ]),
71
            'sorting'    => new Sorting([
72
                'default_order' => Sorting::SORT_DIR_DESC,
73
            ]),
74
            'appearance' => new Appearance([
75
                'width' => 40,
76
                'align' => Appearance::ALIGN_CENTER,
77
            ]),
78
        ]));
79
        
80
        $collection->add(new Column([
81
            'id'         => 'date',
82
            'caption'    => 'invoice.label.date',
83
            'filter'     => new Filter([
84
                'type' => Filter::FILTER_BETWEEN,
85
            ]),
86
            'appearance' => new Appearance([
87
                'width' => 40,
88
                'align' => Appearance::ALIGN_CENTER,
89
            ]),
90
        ]));
91
        
92
        $collection->add(new Column([
93
            'id'         => 'amountPaid',
94
            'caption'    => 'invoice.label.amount_paid',
95
            'filter'     => new Filter([
96
                'type' => Filter::FILTER_BETWEEN,
97
            ]),
98
            'appearance' => new Appearance([
99
                'width' => 40,
100
                'align' => Appearance::ALIGN_CENTER,
101
            ]),
102
        ]));
103
        
104
        $collection->add(new Column([
105
            'id'         => 'amountDue',
106
            'caption'    => 'invoice.label.amount_due',
107
            'filter'     => new Filter([
108
                'type' => Filter::FILTER_BETWEEN,
109
            ]),
110
            'appearance' => new Appearance([
111
                'width' => 40,
112
                'align' => Appearance::ALIGN_CENTER,
113
            ]),
114
        ]));
115
        
116
        $collection->add(new Column([
117
            'id'         => 'dueDate',
118
            'caption'    => 'invoice.label.due_date',
119
            'filter'     => new Filter([
120
                'type' => Filter::FILTER_BETWEEN,
121
            ]),
122
            'appearance' => new Appearance([
123
                'width' => 40,
124
                'align' => Appearance::ALIGN_CENTER,
125
            ]),
126
        ]));
127
        
128
        $collection->add(new Column([
129
            'id'         => 'createdAt',
130
            'caption'    => 'invoice.label.created_at',
131
            'filter'     => new Filter([
132
                'type' => Filter::FILTER_BETWEEN,
133
            ]),
134
            'appearance' => new Appearance([
135
                'width' => 40,
136
                'align' => Appearance::ALIGN_CENTER,
137
            ]),
138
        ]));
139
    }
140
    
141
    public function configureOptions(OptionsInterface $options)
142
    {
143
        $eventHandlers = $options->getEventHandlers();
144
        
145
        $eventHandlers->add(new LoadEventHandler([
146
            'function' => $this->getJavascriptFunctionName('load'),
147
            'route'    => $this->getActionUrl('grid'),
148
        ]));
149
        
150
        $eventHandlers->add(new ClickRowEventHandler([
151
            'function' => $this->getJavascriptFunctionName('click'),
152
            'route'    => $this->getActionUrl('edit'),
153
        ]));
154
        
155
        $eventHandlers->add(new DeleteRowEventHandler([
156
            'function'   => $this->getJavascriptFunctionName('delete'),
157
            'row_action' => DataGridInterface::ACTION_DELETE,
158
            'route'      => $this->getActionUrl('delete'),
159
        ]));
160
        
161
        $eventHandlers->add(new DeleteGroupEventHandler([
162
            'function'     => $this->getJavascriptFunctionName('delete_group'),
163
            'group_action' => DataGridInterface::ACTION_DELETE_GROUP,
164
            'route'        => $this->getActionUrl('delete_group'),
165
        ]));
166
    }
167
    
168
    public function getIdentifier(): string
169
    {
170
        return 'invoice';
171
    }
172
}
173