Failed Conditions
Pull Request — develop (#3348)
by Sergei
10:40
created

Column   A

Complexity

Total Complexity 38

Size/Duplication

Total Lines 323
Duplicated Lines 0 %

Test Coverage

Coverage 98.25%

Importance

Changes 0
Metric Value
wmc 38
eloc 91
dl 0
loc 323
ccs 112
cts 114
cp 0.9825
rs 9.36
c 0
b 0
f 0

36 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setLength() 0 5 1
A setOptions() 0 18 3
A getPlatformOption() 0 3 1
A getScale() 0 3 1
A setScale() 0 5 1
A setFixed() 0 5 1
A setPlatformOptions() 0 5 1
A getFixed() 0 3 1
A getPlatformOptions() 0 3 1
A setType() 0 5 1
A setComment() 0 5 1
A getCustomSchemaOptions() 0 3 1
A getLength() 0 3 1
A getAutoincrement() 0 3 1
A hasCustomSchemaOption() 0 3 1
A getUnsigned() 0 3 1
A getColumnDefinition() 0 3 1
A toArray() 0 16 1
A getNotnull() 0 3 1
A getDefault() 0 3 1
A setUnsigned() 0 5 1
A getCustomSchemaOption() 0 3 1
A setDefault() 0 5 1
A getComment() 0 3 1
A setNotnull() 0 5 1
A getType() 0 3 1
A getPrecision() 0 3 1
A setPlatformOption() 0 5 1
A hasPlatformOption() 0 3 1
A setPrecision() 0 5 1
A setAutoincrement() 0 5 1
A setCustomSchemaOptions() 0 5 1
A getName() 0 6 1
A setColumnDefinition() 0 5 1
A setCustomSchemaOption() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Schema;
6
7
use Doctrine\DBAL\Types\Type;
8
use const E_USER_DEPRECATED;
9
use function array_merge;
10
use function assert;
11
use function is_string;
12
use function method_exists;
13
use function sprintf;
14
use function trigger_error;
15
16
/**
17
 * Object representation of a database column.
18
 */
19
class Column extends AbstractAsset
20
{
21
    /** @var Type */
22
    protected $_type;
23
24
    /** @var int|null */
25
    protected $_length;
26
27
    /** @var int */
28
    protected $_precision;
29
30
    /** @var int */
31
    protected $_scale;
32
33
    /** @var bool */
34
    protected $_unsigned = false;
35
36
    /** @var bool */
37
    protected $_fixed = false;
38
39
    /** @var bool */
40
    protected $_notnull = true;
41
42
    /** @var mixed */
43
    protected $_default;
44
45
    /** @var bool */
46
    protected $_autoincrement = false;
47
48
    /** @var mixed[] */
49
    protected $_platformOptions = [];
50
51
    /** @var string|null */
52
    protected $_columnDefinition = null;
53
54
    /** @var string|null */
55
    protected $_comment = null;
56
57
    /** @var mixed[] */
58
    protected $_customSchemaOptions = [];
59
60
    /**
61
     * Creates a new Column.
62
     *
63
     * @param mixed[] $options
64
     */
65 18276
    public function __construct(string $columnName, Type $type, array $options = [])
66
    {
67 18276
        $this->_setName($columnName);
68 18276
        $this->setType($type);
69 18276
        $this->setOptions($options);
70 18276
    }
71
72 18267
    public function getName() : string
73
    {
74 18267
        $name = parent::getName();
75 18267
        assert(is_string($name));
76
77 18267
        return $name;
78
    }
79
80
    /**
81
     * @param mixed[] $options
82
     */
83 18276
    public function setOptions(array $options) : self
84
    {
85 18276
        foreach ($options as $name => $value) {
86 17808
            $method = 'set' . $name;
87 17808
            if (! method_exists($this, $method)) {
88
                // next major: throw an exception
89 3174
                @trigger_error(sprintf(
90
                    'The "%s" column option is not supported,' .
91 2
                    ' setting it is deprecated and will cause an error in Doctrine 3.0',
92 3174
                    $name
93 3174
                ), E_USER_DEPRECATED);
94
95 3174
                continue;
96
            }
97 17807
            $this->$method($value);
98
        }
99
100 18276
        return $this;
101
    }
102
103 18276
    public function setType(Type $type) : self
104
    {
105 18276
        $this->_type = $type;
106
107 18276
        return $this;
108
    }
109
110 17029
    public function setLength(?int $length) : self
111
    {
112 17029
        $this->_length = $length;
113
114 17029
        return $this;
115
    }
116
117 16791
    public function setPrecision(?int $precision) : self
118
    {
119 16791
        $this->_precision = $precision;
120
121 16791
        return $this;
122
    }
123
124 16790
    public function setScale(?int $scale) : self
125
    {
126 16790
        $this->_scale = $scale;
127
128 16790
        return $this;
129
    }
130
131 16733
    public function setUnsigned(bool $unsigned) : self
132
    {
133 16733
        $this->_unsigned = $unsigned;
134
135 16733
        return $this;
136
    }
137
138 16903
    public function setFixed(bool $fixed) : self
139
    {
140 16903
        $this->_fixed = $fixed;
141
142 16903
        return $this;
143
    }
144
145 18010
    public function setNotnull(bool $notnull) : self
146
    {
147 18010
        $this->_notnull = $notnull;
148
149 18010
        return $this;
150
    }
151
152
    /**
153
     * @param mixed $default
154
     */
155 16811
    public function setDefault($default) : self
156
    {
157 16811
        $this->_default = $default;
158
159 16811
        return $this;
160
    }
161
162
    /**
163
     * @param mixed[] $platformOptions
164
     */
165 13885
    public function setPlatformOptions(array $platformOptions) : self
166
    {
167 13885
        $this->_platformOptions = $platformOptions;
168
169 13885
        return $this;
170
    }
171
172
    /**
173
     * @param mixed $value
174
     */
175 16558
    public function setPlatformOption(string $name, $value) : self
176
    {
177 16558
        $this->_platformOptions[$name] = $value;
178
179 16558
        return $this;
180
    }
181
182 9025
    public function setColumnDefinition(string $value) : self
183
    {
184 9025
        $this->_columnDefinition = $value;
185
186 9025
        return $this;
187
    }
188
189 18068
    public function getType() : Type
190
    {
191 18068
        return $this->_type;
192
    }
193
194 12282
    public function getLength() : ?int
195
    {
196 12282
        return $this->_length;
197
    }
198
199 12272
    public function getPrecision() : ?int
200
    {
201 12272
        return $this->_precision;
202
    }
203
204 12272
    public function getScale() : ?int
205
    {
206 12272
        return $this->_scale;
207
    }
208
209 12402
    public function getUnsigned() : bool
210
    {
211 12402
        return $this->_unsigned;
212
    }
213
214 15656
    public function getFixed() : bool
215
    {
216 15656
        return $this->_fixed;
217
    }
218
219 14201
    public function getNotnull() : bool
220
    {
221 14201
        return $this->_notnull;
222
    }
223
224
    /**
225
     * @return mixed
226
     */
227 16076
    public function getDefault()
228
    {
229 16076
        return $this->_default;
230
    }
231
232
    /**
233
     * @return mixed[]
234
     */
235 16836
    public function getPlatformOptions() : array
236
    {
237 16836
        return $this->_platformOptions;
238
    }
239
240 17950
    public function hasPlatformOption(string $name) : bool
241
    {
242 17950
        return isset($this->_platformOptions[$name]);
243
    }
244
245
    /**
246
     * @return mixed
247
     */
248 14891
    public function getPlatformOption(string $name)
249
    {
250 14891
        return $this->_platformOptions[$name];
251
    }
252
253
    public function getColumnDefinition() : ?string
254
    {
255
        return $this->_columnDefinition;
256
    }
257
258 16638
    public function getAutoincrement() : bool
259
    {
260 16638
        return $this->_autoincrement;
261
    }
262
263 17118
    public function setAutoincrement(bool $flag) : self
264
    {
265 17118
        $this->_autoincrement = $flag;
266
267 17118
        return $this;
268
    }
269
270 16862
    public function setComment(?string $comment) : self
271
    {
272 16862
        $this->_comment = $comment;
273
274 16862
        return $this;
275
    }
276
277 18058
    public function getComment() : ?string
278
    {
279 18058
        return $this->_comment;
280
    }
281
282
    /**
283
     * @param mixed $value
284
     */
285 2757
    public function setCustomSchemaOption(string $name, $value) : self
286
    {
287 2757
        $this->_customSchemaOptions[$name] = $value;
288
289 2757
        return $this;
290
    }
291
292 3225
    public function hasCustomSchemaOption(string $name) : bool
293
    {
294 3225
        return isset($this->_customSchemaOptions[$name]);
295
    }
296
297
    /**
298
     * @return mixed
299
     */
300 3225
    public function getCustomSchemaOption(string $name)
301
    {
302 3225
        return $this->_customSchemaOptions[$name];
303
    }
304
305
    /**
306
     * @param mixed[] $customSchemaOptions
307
     */
308 3227
    public function setCustomSchemaOptions(array $customSchemaOptions) : self
309
    {
310 3227
        $this->_customSchemaOptions = $customSchemaOptions;
311
312 3227
        return $this;
313
    }
314
315
    /**
316
     * @return mixed[]
317
     */
318 16835
    public function getCustomSchemaOptions() : array
319
    {
320 16835
        return $this->_customSchemaOptions;
321
    }
322
323
    /**
324
     * @return mixed[]
325
     */
326 18161
    public function toArray() : array
327
    {
328 18161
        return array_merge([
329 18161
            'name'          => $this->_name,
330 18161
            'type'          => $this->_type,
331 18161
            'default'       => $this->_default,
332 18161
            'notnull'       => $this->_notnull,
333 18161
            'length'        => $this->_length,
334 18161
            'precision'     => $this->_precision,
335 18161
            'scale'         => $this->_scale,
336 18161
            'fixed'         => $this->_fixed,
337 18161
            'unsigned'      => $this->_unsigned,
338 18161
            'autoincrement' => $this->_autoincrement,
339 18161
            'columnDefinition' => $this->_columnDefinition,
340 18161
            'comment' => $this->_comment,
341 18161
        ], $this->_platformOptions, $this->_customSchemaOptions);
342
    }
343
}
344