Passed
Push — master ( 1fa407...e70c1d )
by Anton
04:02
created

Relation::__clone()   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
/**
3
 * Cycle ORM Schema Builder.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
declare(strict_types=1);
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 string|null */
27
    private $inverse = null;
28
29
    /** @var string|null */
30
    private $inverseType = null;
31
32
    /** @var int|null */
33
    private $inverseLoad = null;
34
35
    /**
36
     * Relation constructor.
37
     */
38
    public function __construct()
39
    {
40
        $this->options = new OptionMap();
41
    }
42
43
    /**
44
     * @return OptionMap
45
     */
46
    public function getOptions(): OptionMap
47
    {
48
        return $this->options;
49
    }
50
51
    /**
52
     * @param string $type
53
     * @return Relation
54
     */
55
    public function setType(string $type): Relation
56
    {
57
        $this->type = $type;
58
59
        return $this;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getType(): string
66
    {
67
        if ($this->type === null) {
68
            throw new RelationException("Relation type must be set");
69
        }
70
71
        return $this->type;
72
    }
73
74
    /**
75
     * @param string $target
76
     * @return Relation
77
     */
78
    public function setTarget(string $target): Relation
79
    {
80
        $this->target = $target;
81
82
        return $this;
83
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function getTarget(): string
89
    {
90
        if ($this->target === null) {
91
            throw new RelationException("Relation target must be set");
92
        }
93
94
        return $this->target;
95
    }
96
97
    /**
98
     * @param string $into
99
     * @param string $as
100
     * @param int    $load
101
     * @return Relation
102
     */
103
    public function setInverse(string $into, string $as, ?int $load = null): Relation
104
    {
105
        $this->inverse = $into;
106
        $this->inverseType = $as;
107
        $this->inverseLoad = $load;
108
109
        return $this;
110
    }
111
112
    /**
113
     * @return bool
114
     */
115
    public function isInversed(): bool
116
    {
117
        return $this->inverse != null;
0 ignored issues
show
Bug introduced by Wolfy-J
It seems like you are loosely comparing $this->inverse of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
118
    }
119
120
    /**
121
     * @return string|null
122
     */
123
    public function getInverseName(): ?string
124
    {
125
        return $this->inverse;
126
    }
127
128
    /**
129
     * @return string|null
130
     */
131
    public function getInverseType(): ?string
132
    {
133
        return $this->inverseType;
134
    }
135
136
    /**
137
     * @return int|null
138
     */
139
    public function getInverseLoad(): ?int
140
    {
141
        return $this->inverseLoad;
142
    }
143
144
    /**
145
     * Cloning.
146
     */
147
    public function __clone()
148
    {
149
        $this->options = clone $this->options;
150
    }
151
}