Passed
Push — master ( 5431c9...e4edfb )
by Anton
01:36
created

Field::setTypecast()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
namespace Cycle\Schema\Definition;
11
12
use Cycle\Schema\Exception\FieldException;
13
14
/**
15
 * Field declaration, it's type and mapping to column.
16
 */
17
final class Field
18
{
19
    /** @var array|string */
20
    private $typecast;
21
22
    /** @var string */
23
    private $column;
24
25
    /** @var bool */
26
    private $referenced = false;
27
28
    /**
29
     * @param array|string $typecast
30
     * @return Field
31
     */
32
    public function setTypecast($typecast)
33
    {
34
        $this->typecast = $typecast;
35
36
        return $this;
37
    }
38
39
    /**
40
     * @return bool
41
     */
42
    public function hasTypecast(): bool
43
    {
44
        return $this->typecast !== null;
45
    }
46
47
    /**
48
     * @return array|string
49
     */
50
    public function getTypecast()
51
    {
52
        return $this->typecast;
53
    }
54
55
    /**
56
     * @param string $column
57
     * @return Field
58
     */
59
    public function setColumn(string $column): Field
60
    {
61
        $this->column = $column;
62
63
        return $this;
64
    }
65
66
    /**
67
     * @return string
68
     *
69
     * @throws FieldException
70
     */
71
    public function getColumn(): string
72
    {
73
        if (empty($this->column)) {
74
            throw new FieldException("Column mapping must be set");
75
        }
76
77
        return $this->column;
78
    }
79
80
    /**
81
     * @param bool $indexed
82
     * @return Field
83
     */
84
    public function setReferenced(bool $indexed): Field
85
    {
86
        $this->referenced = $indexed;
87
88
        return $this;
89
    }
90
91
    /**
92
     * @return bool
93
     */
94
    public function isReferenced(): bool
95
    {
96
        return $this->referenced;
97
    }
98
}