Test Failed
Pull Request — master (#36)
by Thomas
02:48
created

Column::factory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace ORM\Dbal;
4
5
/**
6
 * Describes a column of a database table
7
 *
8
 * @package ORM\Dbal
9
 * @author  Thomas Flori <[email protected]>
10
 */
11
class Column
12
{
13
    /** @var string */
14
    protected $name;
15
16
    /** @var TypeInterface */
17
    protected $type;
18
19
    /** @var bool */
20
    protected $hasDefault;
21
22
    /** @var bool */
23
    protected $isNullable;
24
25
    /**
26
     * Column constructor.
27
     *
28
     * @param string $name
29
     * @param TypeInterface $type
30
     * @param bool $hasDefault
31
     * @param bool $isNullable
32
     */
33
    public function __construct($name, TypeInterface $type, $hasDefault, $isNullable)
34
    {
35
        $this->name = $name;
36
        $this->type = $type;
37
        $this->hasDefault = $hasDefault;
38
        $this->isNullable = $isNullable;
39
    }
40
41
    /**
42
     * Returns a new column with params from $columnDefinition
43
     *
44
     * @param array $columnDefinition
45
     * @param TypeInterface $type
46
     * @return static
47
     */
48
    public static function factory($columnDefinition, TypeInterface $type)
49
    {
50
        $name = $columnDefinition['column_name'];
51
        $hasDefault = $columnDefinition['column_default'] !== null;
52
        $isNullable = $columnDefinition['is_nullable'] === true || $columnDefinition['is_nullable'] === 'YES';
53
        return new static($name, $type, $hasDefault, $isNullable);
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getName()
60
    {
61
        return $this->name;
62
    }
63
64
    /**
65
     * @return Type
66
     */
67
    public function getType()
68
    {
69
        return $this->type;
70
    }
71
72
    /**
73
     * @return bool
74
     */
75
    public function hasDefault()
76
    {
77
        return $this->hasDefault;
78
    }
79
80
    /**
81
     * @return bool
82
     */
83
    public function isNullable()
84
    {
85
        return $this->isNullable;
86
    }
87
}
88