Passed
Branch feature-dbal (46f2dd)
by Thomas
03:08
created

Column::factory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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