| Total Complexity | 10 |
| Total Lines | 47 |
| 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->validatePanels($panels); |
||
| 22 | $this->panels = $panels; |
||
| 23 | } |
||
| 24 | |||
| 25 | public function addPanel(string $id, PanelInterface $panel, bool $override = false): void |
||
| 26 | { |
||
| 27 | if (!$override && isset($this->panels[$id])) { |
||
| 28 | throw new \RuntimeException('Panel already exists.'); |
||
| 29 | } |
||
| 30 | |||
| 31 | $this->panels[$id] = $panel; |
||
| 32 | } |
||
| 33 | |||
| 34 | public function getPanel(string $id): PanelInterface |
||
| 35 | { |
||
| 36 | if (!isset($this->panels[$id])) { |
||
| 37 | throw new \InvalidArgumentException(sprintf('Panel "%s" doesn\'t exist.', $id)); |
||
| 38 | } |
||
| 39 | return $this->panels[$id]; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return array<string, PanelInterface> |
||
| 44 | */ |
||
| 45 | public function getPanels(): array |
||
| 48 | } |
||
| 49 | |||
| 50 | private function validatePanels(array $panels): void |
||
| 56 | ); |
||
| 57 | } |
||
| 61 |