| Total Complexity | 9 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | final class Scope |
||
| 13 | { |
||
| 14 | private ?\Spiral\Core\Container $parent = null; |
||
| 15 | private ?self $parentScope = null; |
||
| 16 | |||
| 17 | public function __construct( |
||
| 18 | private readonly ?string $scopeName = null, |
||
| 19 | ) { |
||
| 20 | } |
||
| 21 | |||
| 22 | public function getScopeName(): ?string |
||
| 23 | { |
||
| 24 | return $this->scopeName; |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Link the current scope with its parent scope and container. |
||
| 29 | * |
||
| 30 | * @throws NamedScopeDuplicationException |
||
| 31 | */ |
||
| 32 | public function setParent(\Spiral\Core\Container $parent, self $parentScope): void |
||
| 33 | { |
||
| 34 | $this->parent = $parent; |
||
| 35 | $this->parentScope = $parentScope; |
||
| 36 | |||
| 37 | // Check a scope with the same name is not already registered |
||
| 38 | if ($this->scopeName !== null) { |
||
| 39 | $tmp = $this; |
||
| 40 | while ($tmp->parentScope !== null) { |
||
| 41 | $tmp = $tmp->parentScope; |
||
| 42 | $tmp->scopeName !== $this->scopeName ?: throw new NamedScopeDuplicationException($this->scopeName); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getParent(): ?\Spiral\Core\Container |
||
| 48 | { |
||
| 49 | return $this->parent; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function getParentScope(): ?self |
||
| 55 | } |
||
| 56 | |||
| 57 | public function destruct(): void |
||
| 61 | } |
||
| 62 | } |
||
| 63 |