Completed
Push — master ( c18ee0...6804db )
by Sébastien
14:50
created

AbstractColumnDefinition::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

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