Total Complexity | 7 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | final class PanelCollection |
||
10 | { |
||
11 | /** |
||
12 | * @var array<string, PanelInterface> |
||
13 | */ |
||
14 | private array $panels; |
||
15 | |||
16 | /** |
||
17 | * PanelCollection constructor. |
||
18 | */ |
||
19 | public function __construct(array $panels) |
||
20 | { |
||
21 | $this->panels = $panels; |
||
22 | } |
||
23 | |||
24 | public function addPanel(string $id, PanelInterface $panel, bool $override = false): void |
||
25 | { |
||
26 | if (!$override && isset($this->panels[$id])) { |
||
27 | throw new \RuntimeException('Panel already exists.'); |
||
28 | } |
||
29 | |||
30 | $this->panels[$id] = $panel; |
||
31 | } |
||
32 | |||
33 | public function getPanel(string $id): PanelInterface |
||
34 | { |
||
35 | if (!isset($this->panels[$id])) { |
||
36 | throw new \InvalidArgumentException(sprintf('Panel "%s" doesn\'t exist.', $id)); |
||
37 | } |
||
38 | return $this->panels[$id]; |
||
39 | } |
||
40 | |||
41 | public function getPanels(): array |
||
44 | } |
||
45 | } |
||
46 |