Total Complexity | 9 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Coverage | 95% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | final class RelationMap implements \IteratorAggregate |
||
14 | { |
||
15 | /** @var array<string, Relation> */ |
||
16 | 56 | private array $relations = []; |
|
17 | |||
18 | 56 | public function has(string $name): bool |
|
19 | { |
||
20 | return isset($this->relations[$name]); |
||
21 | 56 | } |
|
22 | |||
23 | 1244 | public function get(string $name): Relation |
|
24 | { |
||
25 | 1244 | if (!$this->has($name)) { |
|
26 | throw new RelationException("Undefined relation `{$name}`"); |
||
27 | } |
||
28 | 910 | ||
29 | return $this->relations[$name]; |
||
30 | 910 | } |
|
31 | 2 | ||
32 | public function set(string $name, Relation $relation): self |
||
33 | { |
||
34 | 908 | if ($this->has($name)) { |
|
35 | throw new RelationException("Relation `{$name}` already exists"); |
||
36 | } |
||
37 | 1242 | ||
38 | $this->relations[$name] = $relation; |
||
39 | 1242 | ||
40 | 2 | return $this; |
|
41 | } |
||
42 | |||
43 | 1242 | public function remove(string $name): self |
|
44 | { |
||
45 | 1242 | unset($this->relations[$name]); |
|
46 | return $this; |
||
47 | } |
||
48 | 280 | ||
49 | /** |
||
50 | 280 | * @return \Traversable<string, Relation> |
|
51 | 280 | */ |
|
52 | public function getIterator(): \Traversable |
||
53 | { |
||
54 | return new \ArrayIterator($this->relations); |
||
55 | } |
||
56 | |||
57 | 1202 | public function __clone() |
|
61 | } |
||
62 | } |
||
63 | } |
||
64 |