Passed
Push — master ( ff3639...8a879c )
by Anton
01:54
created

Relation::isInversed()   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 declare(strict_types=1);
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Cycle\Schema\Definition;
10
11
use Cycle\Schema\Definition\Map\OptionMap;
12
use Cycle\Schema\Exception\RelationException;
13
14
final class Relation
15
{
16
    /** @var OptionMap */
17
    private $options;
18
19
    /** @var string */
20
    private $type;
21
22
    /** @var string */
23
    private $target;
24
25
    /** @var string|null */
26
    private $inverse = null;
27
28
    /** @var string|null */
29
    private $inverseType = null;
30
31
    /**
32
     * Relation constructor.
33
     */
34
    public function __construct()
35
    {
36
        $this->options = new OptionMap();
37
    }
38
39
    /**
40
     * @return OptionMap
41
     */
42
    public function getOptions(): OptionMap
43
    {
44
        return $this->options;
45
    }
46
47
    /**
48
     * @param string $type
49
     * @return Relation
50
     */
51
    public function setType(string $type): Relation
52
    {
53
        $this->type = $type;
54
55
        return $this;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getType(): string
62
    {
63
        if ($this->type === null) {
64
            throw new RelationException("Relation type must be set");
65
        }
66
67
        return $this->type;
68
    }
69
70
    /**
71
     * @param string $target
72
     * @return Relation
73
     */
74
    public function setTarget(string $target): Relation
75
    {
76
        $this->target = $target;
77
78
        return $this;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getTarget(): string
85
    {
86
        if ($this->target === null) {
87
            throw new RelationException("Relation target must be set");
88
        }
89
90
        return $this->target;
91
    }
92
93
    /**
94
     * @param string $into
95
     * @param string $as
96
     * @return Relation
97
     */
98
    public function setInverse(string $into, string $as): Relation
99
    {
100
        $this->inverse = $into;
101
        $this->inverseType = $as;
102
103
        return $this;
104
    }
105
106
    /**
107
     * @return bool
108
     */
109
    public function isInversed(): bool
110
    {
111
        return $this->inverse != null;
0 ignored issues
show
Bug introduced by
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...
112
    }
113
114
    /**
115
     * @return string|null
116
     */
117
    public function getInverseName(): ?string
118
    {
119
        return $this->inverse;
120
    }
121
122
    /**
123
     * @return string|null
124
     */
125
    public function getInverseType(): ?string
126
    {
127
        return $this->inverseType;
128
    }
129
}