Relation   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 28
dl 0
loc 107
ccs 24
cts 27
cp 0.8889
rs 10
c 2
b 0
f 0
wmc 14

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __clone() 0 3 1
A getInverseLoad() 0 3 1
A getOptions() 0 3 1
A isInversed() 0 3 1
A getInverseName() 0 3 1
A getType() 0 7 2
A setInverse() 0 7 1
A getInverseType() 0 3 1
A setTarget() 0 5 1
A setType() 0 5 1
A getTarget() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Definition;
6
7
use Cycle\Schema\Definition\Map\OptionMap;
8
use Cycle\Schema\Exception\RelationException;
9
10
final class Relation
11
{
12
    /** @var OptionMap */
13
    private $options;
14
15
    /** @var string */
16
    private $type;
17
18
    /** @var non-empty-string */
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
19
    private $target;
20
21
    /** @var string|null */
22
    private $inverse = null;
23
24
    /** @var string|null */
25
    private $inverseType = null;
26
27
    /** @var int|null */
28
    private $inverseLoad = null;
29
30
    /**
31
     * Relation constructor.
32
     */
33 1242
    public function __construct()
34
    {
35 1242
        $this->options = new OptionMap();
36 1242
    }
37
38
    public function getOptions(): OptionMap
39
    {
40
        return $this->options;
41
    }
42
43
    public function setType(string $type): self
44
    {
45
        $this->type = $type;
46
47
        return $this;
48
    }
49 1192
50
    public function getType(): string
51 1192
    {
52
        if ($this->type === null) {
53
            throw new RelationException('Relation type must be set');
54
        }
55
56
        return $this->type;
57
    }
58
59 1232
    /**
60
     * @param non-empty-string $target
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
61 1232
     *
62
     */
63 1232
    public function setTarget(string $target): self
64
    {
65
        $this->target = $target;
66
67
        return $this;
68
    }
69 1170
70
    /**
71 1170
     * @return non-empty-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
72 2
     */
73
    public function getTarget(): string
74
    {
75 1168
        if ($this->target === null) {
76
            throw new RelationException('Relation target must be set');
77
        }
78
79
        return $this->target;
80
    }
81
82
    public function setInverse(string $into, string $as, ?int $load = null): self
83 1232
    {
84
        $this->inverse = $into;
85 1232
        $this->inverseType = $as;
86
        $this->inverseLoad = $load;
87 1232
88
        return $this;
89
    }
90
91
    public function isInversed(): bool
92
    {
93 1194
        return $this->inverse !== null;
94
    }
95 1194
96 2
    public function getInverseName(): ?string
97
    {
98
        return $this->inverse;
99 1192
    }
100
101
    public function getInverseType(): ?string
102
    {
103
        return $this->inverseType;
104
    }
105
106
    public function getInverseLoad(): ?int
107
    {
108
        return $this->inverseLoad;
109 256
    }
110
111 256
    /**
112 256
     * Cloning.
113 256
     */
114
    public function __clone()
115 256
    {
116
        $this->options = clone $this->options;
117
    }
118
}
119