Failed Conditions
Pull Request — develop (#3525)
by Jonathan
12:46
created

Column   A

Complexity

Total Complexity 38

Size/Duplication

Total Lines 319
Duplicated Lines 0 %

Test Coverage

Coverage 98.21%

Importance

Changes 0
Metric Value
wmc 38
eloc 90
dl 0
loc 319
rs 9.36
c 0
b 0
f 0
ccs 110
cts 112
cp 0.9821

35 Methods

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