ClientDataGrid::configureColumns()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 118
Code Lines 79

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 118
c 0
b 0
f 0
rs 8.2857
cc 1
eloc 79
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
namespace WellCommerce\Bundle\AppBundle\DataGrid;
13
14
use WellCommerce\Bundle\CoreBundle\DataGrid\AbstractDataGrid;
15
use WellCommerce\Component\DataGrid\Column\Column;
16
use WellCommerce\Component\DataGrid\Column\ColumnCollection;
17
use WellCommerce\Component\DataGrid\Column\Options\Appearance;
18
use WellCommerce\Component\DataGrid\Column\Options\Filter;
19
use WellCommerce\Component\DataGrid\Configuration\EventHandler\LoadedEventHandler;
20
use WellCommerce\Component\DataGrid\Configuration\EventHandler\ProcessEventHandler;
21
use WellCommerce\Component\DataGrid\Options\OptionsInterface;
22
23
/**
24
 * Class ClientDataGrid
25
 *
26
 * @author  Adam Piotrowski <[email protected]>
27
 */
28
class ClientDataGrid extends AbstractDataGrid
29
{
30
    /**
31
     * @var ClientGroupFilter
32
     */
33
    protected $clientGroupFilter;
34
    
35
    public function __construct(ClientGroupFilter $clientGroupFilter)
36
    {
37
        $this->clientGroupFilter = $clientGroupFilter;
38
    }
39
    
40
    public function configureColumns(ColumnCollection $collection)
41
    {
42
        $collection->add(new Column([
43
            'id'         => 'id',
44
            'caption'    => 'common.label.id',
45
            'appearance' => new Appearance([
46
                'width'   => 60,
47
                'visible' => false,
48
            ]),
49
            'filter'     => new Filter([
50
                'type' => Filter::FILTER_BETWEEN,
51
            ]),
52
        ]));
53
        
54
        $collection->add(new Column([
55
            'id'         => 'firstName',
56
            'caption'    => 'common.label.first_name',
57
            'appearance' => new Appearance([
58
                'width' => 60,
59
                'align' => Appearance::ALIGN_LEFT,
60
            ]),
61
        ]));
62
        
63
        $collection->add(new Column([
64
            'id'         => 'lastName',
65
            'caption'    => 'common.label.last_name',
66
            'appearance' => new Appearance([
67
                'width' => 80,
68
                'align' => Appearance::ALIGN_LEFT,
69
            ]),
70
        ]));
71
        
72
        $collection->add(new Column([
73
            'id'         => 'companyName',
74
            'caption'    => 'client.label.address.company',
75
            'appearance' => new Appearance([
76
                'width' => 100,
77
                'align' => Appearance::ALIGN_CENTER,
78
            ]),
79
        ]));
80
        
81
        $collection->add(new Column([
82
            'id'         => 'vatId',
83
            'caption'    => 'client.label.address.vat_id',
84
            'appearance' => new Appearance([
85
                'width' => 60,
86
                'align' => Appearance::ALIGN_CENTER,
87
            ]),
88
        ]));
89
        
90
        $collection->add(new Column([
91
            'id'         => 'email',
92
            'caption'    => 'common.label.email',
93
            'appearance' => new Appearance([
94
                'width' => 60,
95
                'align' => Appearance::ALIGN_CENTER,
96
            ]),
97
        ]));
98
        
99
        $collection->add(new Column([
100
            'id'         => 'phone',
101
            'caption'    => 'common.label.phone',
102
            'appearance' => new Appearance([
103
                'width' => 80,
104
                'align' => Appearance::ALIGN_CENTER,
105
            ]),
106
        ]));
107
        
108
        $collection->add(new Column([
109
            'id'         => 'groupName',
110
            'caption'    => 'common.label.client_group',
111
            'filter'     => new Filter([
112
                'type'            => Filter::FILTER_TREE,
113
                'filtered_column' => 'groupId',
114
                'options'         => $this->clientGroupFilter->getOptions(),
115
            ]),
116
            'appearance' => new Appearance([
117
                'width' => 100,
118
                'align' => Appearance::ALIGN_CENTER,
119
            ]),
120
        ]));
121
        
122
        $collection->add(new Column([
123
            'id'         => 'createdAt',
124
            'caption'    => 'common.label.created_at',
125
            'filter'     => new Filter([
126
                'type' => Filter::FILTER_BETWEEN,
127
            ]),
128
            'appearance' => new Appearance([
129
                'width' => 40,
130
                'align' => Appearance::ALIGN_CENTER,
131
            ]),
132
        ]));
133
        
134
        $collection->add(new Column([
135
            'id'         => 'lastActive',
136
            'caption'    => 'client.label.last_active',
137
            'filter'     => new Filter([
138
                'type' => Filter::FILTER_BETWEEN,
139
            ]),
140
            'appearance' => new Appearance([
141
                'width' => 60,
142
                'align' => Appearance::ALIGN_CENTER,
143
            ]),
144
        ]));
145
        
146
        $collection->add(new Column([
147
            'id'         => 'cart',
148
            'caption'    => 'client.label.cart',
149
            'filter'     => new Filter([
150
                'type' => Filter::FILTER_BETWEEN,
151
            ]),
152
            'appearance' => new Appearance([
153
                'width' => 60,
154
                'align' => Appearance::ALIGN_CENTER,
155
            ]),
156
        ]));
157
    }
158
    
159
    public function configureOptions(OptionsInterface $options)
160
    {
161
        parent::configureOptions($options);
162
        
163
        $eventHandlers = $options->getEventHandlers();
164
        
165
        $eventHandlers->add(new ProcessEventHandler([
166
            'function' => $this->getJavascriptFunctionName('process'),
167
        ]));
168
        
169
        $eventHandlers->add(new LoadedEventHandler([
170
            'function' => $this->getJavascriptFunctionName('loaded'),
171
        ]));
172
    }
173
    
174
    public function getIdentifier(): string
175
    {
176
        return 'client';
177
    }
178
}
179