| Total Complexity | 9 |
| Total Lines | 68 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | final class RelationMap implements \IteratorAggregate |
||
| 16 | { |
||
| 17 | /** @var Relation[] */ |
||
| 18 | private $relations = []; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param string $name |
||
| 22 | * @return bool |
||
| 23 | */ |
||
| 24 | public function has(string $name): bool |
||
| 25 | { |
||
| 26 | return isset($this->relations[$name]); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param string $name |
||
| 31 | * @return Relation |
||
| 32 | */ |
||
| 33 | public function get(string $name): Relation |
||
| 34 | { |
||
| 35 | if (!$this->has($name)) { |
||
| 36 | throw new RelationException("Undefined relation `{$name}`"); |
||
| 37 | } |
||
| 38 | |||
| 39 | return $this->relations[$name]; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param string $name |
||
| 44 | * @param Relation $relation |
||
| 45 | * @return RelationMap |
||
| 46 | */ |
||
| 47 | public function set(string $name, Relation $relation): self |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param string $name |
||
| 60 | * @return RelationMap |
||
| 61 | */ |
||
| 62 | public function remove(string $name): self |
||
| 63 | { |
||
| 64 | unset($this->relations[$name]); |
||
| 65 | return $this; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @return Relation[]|\Traversable |
||
| 70 | */ |
||
| 71 | public function getIterator() |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Cloning. |
||
| 78 | */ |
||
| 79 | public function __clone() |
||
| 85 | } |