AbstractColumnDefinition   B
last analyzed

Complexity

Total Complexity 38

Size/Duplication

Total Lines 432
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 62%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 38
lcom 3
cbo 0
dl 0
loc 432
ccs 62
cts 100
cp 0.62
rs 8.3999
c 1
b 1
f 0

33 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setName() 0 6 1
A getName() 0 4 1
A getTableName() 0 4 1
A setTableName() 0 9 2
A setSchemaName() 0 9 2
A getSchemaName() 0 4 1
A getOrdinalPosition() 0 4 1
A setOrdinalPosition() 0 6 1
A getColumnDefault() 0 4 1
A setColumnDefault() 0 6 1
A setIsNullable() 0 6 1
A isNullable() 0 4 1
A setIsPrimary() 0 6 1
A isPrimary() 0 4 1
A getDataType() 0 4 1
A setDataType() 0 6 1
A getNativeDataType() 0 4 1
A setNativeDataType() 0 6 1
A setAlias() 0 6 1
A getAlias() 0 4 1
A setTableAlias() 0 9 2
A getTableAlias() 0 4 1
A setCatalog() 0 6 1
A getCatalog() 0 4 1
A setIsGroup() 0 6 1
A isGroup() 0 4 1
A isComputed() 0 4 1
A isNumeric() 0 4 1
A isText() 0 4 1
A isDate() 0 4 1
A isDatetime() 0 4 1
A toArray() 0 14 3
1
<?php
2
3
namespace Soluble\Datatype\Column\Definition;
4
5
abstract class AbstractColumnDefinition
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $name = null;
11
12
    /**
13
     * @var string
14
     */
15
    protected $tableName = null;
16
17
    /**
18
     * @var string
19
     */
20
    protected $schemaName = null;
21
22
    /**
23
     * @var
24
     */
25
    protected $ordinalPosition = null;
26
27
    /**
28
     * @var string
29
     */
30
    protected $columnDefault = null;
31
32
    /**
33
     * @var string
34
     */
35
    protected $dataType = null;
36
37
    /**
38
     * @var string
39
     */
40
    protected $nativeDataType = null;
41
42
    /**
43
     * @var string
44
     */
45
    protected $alias;
46
47
    /**
48
     * @var string
49
     */
50
    protected $tableAlias;
51
52
    /**
53
     * @var string
54
     */
55
    protected $catalog;
56
57
    /**
58
     * @var bool
59
     */
60
    protected $isPrimary = false;
61
62
    /**
63
     * @var bool
64
     */
65
    protected $isNullable = false;
66
67
    /**
68
     * @var bool
69
     */
70
    protected $isGroup = false;
71
72
    /**
73
     * Constructor.
74
     *
75
     * @param string $name
76
     * @param string $tableName
77
     * @param string $schemaName
78
     */
79
    public function __construct($name, $tableName = null, $schemaName = null)
80
    {
81
        $this->setName($name);
82
        $this->setTableName($tableName);
83
        $this->setSchemaName($schemaName);
84
    }
85
86
    /**
87
     * Set name.
88
     *
89
     * @param string $name
90
     *
91
     * @return AbstractColumnDefinition
92
     */
93
    public function setName($name)
94 3
    {
95
        $this->name = $name;
96 3
97 3
        return $this;
98 3
    }
99 3
100
    /**
101
     * Get name.
102
     *
103
     * @return string
104
     */
105
    public function getName()
106
    {
107 3
        return $this->name;
108
    }
109 3
110 3
    /**
111
     * Get table name.
112
     *
113
     * @return string
114
     */
115
    public function getTableName()
116
    {
117
        return $this->tableName;
118 2
    }
119
120 2
    /**
121
     * Set table name.
122
     *
123
     * @param string $tableName
124
     *
125
     * @return AbstractColumnDefinition
126
     */
127
    public function setTableName($tableName)
128 2
    {
129
        if (trim($tableName) == '') {
130 2
            $tableName = null;
131
        }
132
        $this->tableName = $tableName;
133
134
        return $this;
135
    }
136
137
    /**
138
     * Set schema name.
139 3
     *
140
     * @param string $schemaName
141 3
     *
142 1
     * @return AbstractColumnDefinition
143 1
     */
144 3
    public function setSchemaName($schemaName)
145 3
    {
146
        if (trim($schemaName) == '') {
147
            $schemaName = null;
148
        }
149
        $this->schemaName = $schemaName;
150
151
        return $this;
152
    }
153
154 3
    /**
155
     * Get schema name.
156 3
     *
157 2
     * @return string
158 2
     */
159 3
    public function getSchemaName()
160 3
    {
161
        return $this->schemaName;
162
    }
163
164
    /**
165
     * @return int $ordinalPosition
166
     */
167
    public function getOrdinalPosition()
168 2
    {
169
        return $this->ordinalPosition;
170 2
    }
171
172
    /**
173
     * @param int $ordinalPosition to set
174
     *
175
     * @return AbstractColumnDefinition
176 1
     */
177
    public function setOrdinalPosition($ordinalPosition)
178 1
    {
179
        $this->ordinalPosition = $ordinalPosition;
180
181
        return $this;
182
    }
183
184
    /**
185 1
     * @return null|string the $columnDefault
186
     */
187 1
    public function getColumnDefault()
188 1
    {
189
        return $this->columnDefault;
190
    }
191
192
    /**
193
     * @param string $columnDefault to set
194 1
     *
195
     * @return AbstractColumnDefinition
196 1
     */
197
    public function setColumnDefault($columnDefault)
198
    {
199
        $this->columnDefault = $columnDefault;
200
201
        return $this;
202
    }
203 1
204
    /**
205 1
     * @param bool $isNullable to set
206 1
     *
207
     * @return AbstractColumnDefinition
208
     */
209
    public function setIsNullable($isNullable)
210
    {
211
        $this->isNullable = $isNullable;
212
213
        return $this;
214 1
    }
215
216 1
    /**
217 1
     * @return bool $isNullable
218
     */
219
    public function isNullable()
220
    {
221
        return $this->isNullable;
222
    }
223 1
224
    /**
225 1
     * @param bool $isPrimary to set
226
     *
227
     * @return AbstractColumnDefinition
228
     */
229
    public function setIsPrimary($isPrimary)
230
    {
231
        $this->isPrimary = $isPrimary;
232
233 1
        return $this;
234
    }
235 1
236 1
    /**
237
     * @return bool $isPrimary
238
     */
239
    public function isPrimary()
240
    {
241
        return $this->isPrimary;
242 1
    }
243
244 1
    /**
245
     * @return null|string the $dataType
246
     */
247
    public function getDataType()
248
    {
249
        return $this->dataType;
250
    }
251
252
    /**
253
     * @param string $dataType the $dataType to set
254
     *
255
     * @return AbstractColumnDefinition
256
     */
257
    public function setDataType($dataType)
258
    {
259
        $this->dataType = $dataType;
260
261
        return $this;
262
    }
263
264
    /**
265
     * @return null|string the $nativeDataType
266
     */
267
    public function getNativeDataType()
268
    {
269
        return $this->nativeDataType;
270
    }
271
272
    /**
273
     * @param string $nativeDataType the $dataType to set
274
     *
275
     * @return AbstractColumnDefinition
276
     */
277
    public function setNativeDataType($nativeDataType)
278
    {
279
        $this->nativeDataType = $nativeDataType;
280
281
        return $this;
282
    }
283
284
    /**
285
     * @param string $alias column alias name
286
     *
287
     * @return AbstractColumnDefinition
288
     */
289
    public function setAlias($alias)
290
    {
291
        $this->alias = $alias;
292
293
        return $this;
294
    }
295
296
    /**
297
     * @return string column alais
298
     */
299
    public function getAlias()
300
    {
301
        return $this->alias;
302
    }
303
304
    /**
305
     * @param string $tableAlias table alias name
306
     *
307
     * @return AbstractColumnDefinition
308
     */
309
    public function setTableAlias($tableAlias)
310
    {
311
        if (trim($tableAlias) == '') {
312
            $tableAlias = null;
313
        }
314
        $this->tableAlias = $tableAlias;
315
316
        return $this;
317
    }
318
319
    /**
320
     * @return string table alias
321
     */
322
    public function getTableAlias()
323
    {
324
        return $this->tableAlias;
325
    }
326
327
    /**
328
     * @param string $catalog db catalog
329
     *
330
     * @return AbstractColumnDefinition
331
     */
332
    public function setCatalog($catalog)
333
    {
334
        $this->catalog = $catalog;
335
336
        return $this;
337
    }
338
339
    /**
340
     * @return string catalog
341
     */
342
    public function getCatalog()
343
    {
344
        return $this->catalog;
345
    }
346
347
    /**
348
     * @param bool $isGroup when the column is grouped
349
     *
350
     * @return AbstractColumnDefinition
351
     */
352
    public function setIsGroup($isGroup)
353
    {
354 1
        $this->isGroup = $isGroup;
355
356 1
        return $this;
357 1
    }
358
359
    /**
360
     * Whether the column originates from a sql group function.
361
     *
362
     * @return bool
363
     */
364
    public function isGroup()
365 1
    {
366
        return $this->isGroup;
367 1
    }
368
369
    /**
370
     * @return bool
371
     */
372
    public function isComputed()
373
    {
374
        return $this->tableName == '';
375
    }
376
377
    /**
378
     * Tells whether the column is numeric.
379
     *
380
     * @return bool
381
     */
382
    public function isNumeric()
383
    {
384
        return $this instanceof NumericColumnInterface;
385
    }
386
387
    /**
388
     * Tells whether the column is textual.
389
     *
390
     * @return bool
391
     */
392
    public function isText()
393
    {
394
        return $this instanceof TextColumnInterface;
395
    }
396
397
    /**
398
     * Tells whether the column is a date.
399
     *
400
     * @return bool
401
     */
402
    public function isDate()
403
    {
404
        return $this instanceof DateColumnInterface;
405
    }
406
407
    /**
408
     * Tells whether the column is a timestamp.
409
     *
410
     * @return bool
411
     */
412
    public function isDatetime()
413
    {
414
        return $this instanceof DatetimeColumnInterface;
415
    }
416
417
    /**
418
     * Return an array version of the column definition.
419
     *
420
     * @return array
421
     */
422
    public function toArray()
423
    {
424 1
        $reflectionClass = new \ReflectionClass(get_class($this));
425
        $array = [];
426 1
        foreach ($reflectionClass->getProperties() as $property) {
427 1
            if ($property->isProtected()) {
428 1
                $property->setAccessible(true);
429 1
                $array[$property->getName()] = $property->getValue($this);
430 1
                $property->setAccessible(false);
431 1
            }
432 1
        }
433 1
434 1
        return $array;
435 1
    }
436
}
437