Completed
Pull Request — master (#1)
by
unknown
16:41
created

FieldDescriptor::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 21
nc 2
nop 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\ActivityLogBundle\Compatibility;
13
14
use JMS\Serializer\Annotation\Exclude;
15
use JMS\Serializer\Annotation\Expose;
16
use Sulu\Component\Rest\ListBuilder\FieldDescriptorInterface;
17
use Sulu\Component\Rest\ListBuilder\Metadata\PropertyMetadata;
18
19
/**
20
 * Base class for all field-descriptor.
21
 */
22
class FieldDescriptor implements FieldDescriptorInterface
23
{
24
    /**
25
     * The name of the field in the database.
26
     *
27
     * @var string
28
     * @Expose
29
     */
30
    private $name;
31
32
    /**
33
     * The translation name.
34
     *
35
     * @var string
36
     * @Expose
37
     */
38
    private $translation;
39
40
    /**
41
     * Defines whether the field is disabled or not.
42
     *
43
     * @var bool
44
     * @Expose
45
     */
46
    private $disabled;
47
48
    /**
49
     * Defines whether the field is hideable or not.
50
     *
51
     * @var bool
52
     * @Expose
53
     */
54
    private $default;
55
56
    /**
57
     * Defines if this field is sortable.
58
     *
59
     * @var bool
60
     * @Expose
61
     */
62
    private $sortable;
63
64
    /**
65
     * The type of the field (only used for special fields like dates).
66
     *
67
     * @var string
68
     * @Expose
69
     */
70
    private $type;
71
72
    /**
73
     * The width of the field in a table.
74
     *
75
     * @var string
76
     * @Expose
77
     */
78
    private $width;
79
80
    /**
81
     * The minimal with of the field in the table.
82
     *
83
     * @var string
84
     * @Expose
85
     */
86
    private $minWidth;
87
88
    /**
89
     * Defines whether the field is editable in the table or not.
90
     *
91
     * @var bool
92
     * @Expose
93
     */
94
    private $editable;
95
96
    /**
97
     * The css class of the column.
98
     *
99
     * @var string
100
     * @Expose
101
     */
102
    private $class;
103
104
    /**
105
     * @var PropertyMetadata
106
     * @Exclude
107
     */
108
    private $metadata;
109
110
    public function __construct(
111
        $name,
112
        $translation = null,
113
        $disabled = false,
114
        $default = false,
115
        $type = '',
116
        $width = '',
117
        $minWidth = '',
118
        $sortable = true,
119
        $editable = false,
120
        $cssClass = ''
121
    ) {
122
        $this->name = $name;
123
        $this->disabled = $disabled;
124
        $this->default = $default;
125
        $this->sortable = $sortable;
126
        $this->type = $type;
127
        $this->width = $width;
128
        $this->minWidth = $minWidth;
129
        $this->editable = $editable;
130
        $this->translation = $translation == null ? $name : $translation;
131
        $this->class = $cssClass;
132
    }
133
134
    /**
135
     * {@inheritdoc}
136
     */
137
    public function getName()
138
    {
139
        return $this->name;
140
    }
141
142
    /**
143
     * {@inheritdoc}
144
     */
145
    public function getDisabled()
146
    {
147
        return $this->disabled;
148
    }
149
150
    /**
151
     * {@inheritdoc}
152
     */
153
    public function getTranslation()
154
    {
155
        return $this->translation;
156
    }
157
158
    /**
159
     * {@inheritdoc}
160
     */
161
    public function getType()
162
    {
163
        return $this->type;
164
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169
    public function getWidth()
170
    {
171
        return $this->width;
172
    }
173
174
    /**
175
     * {@inheritdoc}
176
     */
177
    public function getDefault()
178
    {
179
        return $this->default;
180
    }
181
182
    /**
183
     * {@inheritdoc}
184
     */
185
    public function getSortable()
186
    {
187
        return $this->sortable;
188
    }
189
190
    /**
191
     * {@inheritdoc}
192
     */
193
    public function getEditable()
194
    {
195
        return $this->editable;
196
    }
197
198
    /**
199
     * {@inheritdoc}
200
     */
201
    public function getMinWidth()
202
    {
203
        return $this->minWidth;
204
    }
205
206
    /**
207
     * {@inheritdoc}
208
     */
209
    public function getClass()
210
    {
211
        return $this->class;
212
    }
213
214
    /**
215
     * {@inheritdoc}
216
     */
217
    public function getMetadata()
218
    {
219
        return $this->metadata;
220
    }
221
222
    /**
223
     * Sets metadata for property.
224
     *
225
     * @param PropertyMetadata $metadata
226
     */
227
    public function setMetadata($metadata)
228
    {
229
        $this->metadata = $metadata;
230
    }
231
232
    /**
233
     * {@inheritdoc}
234
     */
235
    public function compare(FieldDescriptorInterface $other)
236
    {
237
        if (!$other instanceof self) {
238
            return false;
239
        }
240
241
        return $this->getName() === $other->getName()
242
            && $this->getType() === $other->getType();
243
    }
244
}
245