Passed
Pull Request — master (#11)
by Rustam
12:00
created

PanelCollection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 10
c 1
b 0
f 0
dl 0
loc 35
ccs 0
cts 12
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPanels() 0 3 1
A addPanel() 0 7 3
A getPanel() 0 6 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Viewer;
6
7
use Yiisoft\Yii\Debug\Viewer\Panels\PanelInterface;
8
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
42
    {
43
        return $this->panels;
44
    }
45
}
46