Completed
Push — master ( bd6b93...2911b9 )
by Rougin
02:46
created

Column::getReferencedField()   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

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Rougin\Describe;
4
5
/**
6
 * Column Class
7
 *
8
 * Stores a column information from the results given.
9
 *
10
 * @package Describe
11
 * @author  Rougin Royce Gutib <[email protected]>
12
 */
13
class Column
14
{
15
    /**
16
     * @var boolean
17
     */
18
    protected $autoIncrement = FALSE;
19
20
    /**
21
     * @var string
22
     */
23
    protected $dataType;
24
25
    /**
26
     * @var string
27
     */
28
    protected $defaultValue = '';
29
30
    /**
31
     * @var string
32
     */
33
    protected $field;
34
35
    /**
36
     * @var boolean
37
     */
38
    protected $foreign = FALSE;
39
40
    /**
41
     * @var integer
42
     */
43
    protected $length = 0;
44
45
    /**
46
     * @var boolean
47
     */
48
    protected $null = FALSE;
49
50
    /**
51
     * @var boolean
52
     */
53
    protected $primary = FALSE;
54
55
    /**
56
     * @var string
57
     */
58
    protected $referencedField;
59
60
    /**
61
     * @var string
62
     */
63
    protected $referencedTable;
64
65
    /**
66
     * @var boolean
67
     */
68
    protected $unique = FALSE;
69
70
    /**
71
     * @var boolean
72
     */
73
    protected $unsigned = FALSE;
74
75
    /**
76
     * Gets the data type.
77
     * 
78
     * @return string
79
     */
80
    public function getDataType()
81
    {
82
        return $this->dataType;
83
    }
84
85
    /**
86
     * Gets the default value.
87
     * 
88
     * @return string
89
     */
90
    public function getDefaultValue()
91
    {
92
        return $this->defaultValue;
93
    }
94
95
    /**
96
     * Gets the column description.
97
     * 
98
     * @return string
99
     */
100
    public function getField()
101
    {
102
        return $this->field;
103
    }
104
105
    /**
106
     * Gets the foreign field.
107
     * 
108
     * @return string
109
     */
110
    public function getReferencedField()
111
    {
112
        return $this->referencedField;
113
    }
114
115
    /**
116
     * Gets the foreign table.
117
     * 
118
     * @return string
119
     */
120
    public function getReferencedTable()
121
    {
122
        return $this->referencedTable;
123
    }
124
125
    /**
126
     * Gets the field's length.
127
     * 
128
     * @return integer
129
     */
130
    public function getLength()
131
    {
132
        return $this->length;
133
    }
134
135
    /**
136
     * Gets the data type.
137
     * 
138
     * @return string
139
     */
140
    public function get_data_type()
141
    {
142
        return $this->dataType;
143
    }
144
145
    /**
146
     * Gets the default value.
147
     * 
148
     * @return string
149
     */
150
    public function get_default_value()
151
    {
152
        return $this->defaultValue;
153
    }
154
155
    /**
156
     * Gets the column description.
157
     * 
158
     * @return string
159
     */
160 6
    public function get_field()
161
    {
162 6
        return $this->field;
163
    }
164
165
    /**
166
     * Gets the foreign field.
167
     * 
168
     * @return string
169
     */
170
    public function get_referenced_field()
171
    {
172
        return $this->referencedField;
173
    }
174
175
    /**
176
     * Gets the foreign table.
177
     * 
178
     * @return string
179
     */
180
    public function get_referenced_table()
181
    {
182
        return $this->referencedTable;
183
    }
184
185
    /**
186
     * Gets the field's length.
187
     * 
188
     * @return string
189
     */
190
    public function get_length()
191
    {
192
        return $this->length;
193
    }
194
195
    /**
196
     * Check if the field is an auto incrementing field
197
     * 
198
     * @return boolean
199
     */
200
    public function isAutoIncrement()
201
    {
202
        return $this->autoIncrement;
203
    }
204
205
    /**
206
     * Check if the field is a foreign key
207
     * 
208
     * @return boolean
209
     */
210
    public function isForeignKey()
211
    {
212
        return $this->foreign;
213
    }
214
215
    /**
216
     * Check if the field accept NULL values
217
     * 
218
     * @return boolean
219
     */
220
    public function isNull()
221
    {
222
        return $this->null;
223
    }
224
225
    /**
226
     * Check if the field is a primary key
227
     * 
228
     * @return boolean
229
     */
230 6
    public function isPrimaryKey()
231
    {
232 6
        return $this->primary;
233
    }
234
235
    /**
236
     * Check if field is unique
237
     * 
238
     * @return boolean
239
     */
240
    public function isUnique()
241
    {
242
        return $this->unique;
243
    }
244
245
    /**
246
     * Check if field is unsigned
247
     * 
248
     * @return boolean
249
     */
250
    public function isUnsigned()
251
    {
252
        return $this->unsigned;
253
    }
254
255
    /**
256
     * Check if the field is an auto incrementing field
257
     * 
258
     * @return boolean
259
     */
260
    public function is_auto_increment()
261
    {
262
        return $this->autoIncrement;
263
    }
264
265
    /**
266
     * Check if the field is a foreign key
267
     * 
268
     * @return boolean
269
     */
270
    public function is_foreign_key()
271
    {
272
        return $this->foreign;
273
    }
274
275
    /**
276
     * Check if the field accept NULL values
277
     * 
278
     * @return boolean
279
     */
280
    public function is_null()
281
    {
282
        return $this->null;
283
    }
284
285
    /**
286
     * Check if the field is a primary key
287
     * 
288
     * @return boolean
289
     */
290
    public function is_primary_key()
291
    {
292
        return $this->primary;
293
    }
294
295
    /**
296
     * Check if field is unique
297
     * 
298
     * @return boolean
299
     */
300
    public function is_unique()
301
    {
302
        return $this->unique;
303
    }
304
305
    /**
306
     * Check if field is unsigned
307
     * 
308
     * @return boolean
309
     */
310
    public function is_unsigned()
311
    {
312
        return $this->unsigned;
313
    }
314
315
    /**
316
     * Sets the auto increment.
317
     * 
318
     * @param boolean $autoIncrement
319
     */
320 12
    public function setAutoIncrement($autoIncrement)
321
    {
322 12
        $this->autoIncrement = $autoIncrement;
323
324 12
        return $this;
325
    }
326
327
    /**
328
     * Sets the data type.
329
     * 
330
     * @param string $dataType
331
     */
332 12
    public function setDataType($dataType)
333
    {
334
        $dataTypes = [
335 12
            'int' => 'integer',
336 12
            'varchar' => 'string',
337
            'text' => 'string'
338 12
        ];
339
340 12
        foreach ($dataTypes as $key => $value) {
341 12
            if (strpos($dataType, $key) !== FALSE) {
342 12
                $dataType = $value;
343 12
            }
344 12
        }
345
346 12
        $this->dataType = $dataType;
347 12
    }
348
349
    /**
350
     * Sets the default value.
351
     * 
352
     * @param string $defaultValue
353
     */
354 12
    public function setDefaultValue($defaultValue)
355
    {
356 12
        $this->defaultValue = $defaultValue;
357
358 12
        return $this;
359
    }
360
361
    /**
362
     * Sets the column's description.
363
     * 
364
     * @param string $field
365
     */
366 12
    public function setField($field)
367
    {
368 12
        $this->field = $field;
369
370 12
        return $this;
371
    }
372
373
    /**
374
     * Sets the field as a foreign key.
375
     * 
376
     * @param boolean $foreign
377
     */
378
    public function setForeign($foreign)
379
    {
380
        $this->foreign = $foreign;
381
382
        return $this;
383
    }
384
385
    /**
386
     * Sets the foreign field.
387
     * 
388
     * @param string $referencedField
389
     */
390
    public function setReferencedField($referencedField)
391
    {
392
        $this->referencedField = $referencedField;
393
394
        return $this;
395
    }
396
397
    /**
398
     * Sets the foreign table.
399
     * 
400
     * @param string $foreignTable
401
     */
402
    public function setReferencedTable($foreignTable)
403
    {
404
        $this->referencedTable = $foreignTable;
405
406
        return $this;
407
    }
408
409
    /**
410
     * Sets the field's length.
411
     * 
412
     * @param integer $length
413
     */
414
    public function setLength($length)
415
    {
416
        $this->length = $length;
417
418
        return $this;
419
    }
420
421
    /**
422
     * Sets if field accepts NULL values.
423
     * 
424
     * @param boolean $null
425
     */
426 12
    public function setNull($null = TRUE)
427
    {
428 12
        $this->null = $null;
429
430 12
        return $this;
431
    }
432
433
    /**
434
     * Sets if field is a primary key.
435
     * 
436
     * @param boolean $primary
437
     */
438 12
    public function setPrimary($primary = TRUE)
439
    {
440 12
        $this->primary = $primary;
441
442 12
        return $this;
443
    }
444
445
    /**
446
     * Sets if field is a unique key.
447
     * 
448
     * @param boolean $unique
449
     */
450
    public function setUnique($unique = TRUE)
451
    {
452
        $this->unique = $unique;
453
454
        return $this;
455
    }
456
457
    /**
458
     * Sets if field is an unsigned key.
459
     * 
460
     * @param boolean $unsigned
461
     */
462
    public function setUnsigned($unsigned = TRUE)
463
    {
464
        $this->unsigned = $unsigned;
465
466
        return $this;
467
    }
468
}
469