Completed
Push — master ( 67a451...578537 )
by Anton
40:44 queued 34:10
created

Relation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Definition\Map\OptionMap;
13
use Cycle\Schema\Exception\RelationException;
14
15
final class Relation
16
{
17
    /** @var OptionMap */
18
    private $options;
19
20
    /** @var string */
21
    private $type;
22
23
    /** @var string */
24
    private $target;
25
26
    /** @var bool */
27
    private $inverse = false;
28
29
    /**
30
     * Relation constructor.
31
     */
32
    public function __construct()
33
    {
34
        $this->options = new OptionMap();
35
    }
36
37
    /**
38
     * @return OptionMap
39
     */
40
    public function getOptions(): OptionMap
41
    {
42
        return $this->options;
43
    }
44
45
    /**
46
     * @param string $type
47
     * @return Relation
48
     */
49
    public function setType(string $type): Relation
50
    {
51
        $this->type = $type;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getType(): string
60
    {
61
        if ($this->type === null) {
62
            throw new RelationException("Relation type must be set");
63
        }
64
65
        return $this->type;
66
    }
67
68
    /**
69
     * @param string $target
70
     * @return Relation
71
     */
72
    public function setTarget(string $target): Relation
73
    {
74
        $this->target = $target;
75
76
        return $this;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getTarget(): string
83
    {
84
        if ($this->target === null) {
85
            throw new RelationException("Relation target must be set");
86
        }
87
88
        return $this->target;
89
    }
90
91
    /**
92
     * @param bool $inverse
93
     * @return Relation
94
     */
95
    public function setInverse(bool $inverse): Relation
96
    {
97
        $this->inverse = $inverse;
98
        return $this;
99
    }
100
101
    /**
102
     * @return bool
103
     */
104
    public function isInverse(): bool
105
    {
106
        return $this->inverse;
107
    }
108
}