Passed
Push — master ( 1d5530...fba2a1 )
by Nico
56:37 queued 25:57
created

PanelLayer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 29
ccs 6
cts 7
cp 0.8571
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A renderCell() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Map\VisualPanel\Layer;
6
7
use RuntimeException;
8
use Stu\Lib\Map\VisualPanel\AbstractVisualPanel;
9
use Stu\Lib\Map\VisualPanel\Layer\Data\CellDataInterface;
10
use Stu\Lib\Map\VisualPanel\Layer\Render\LayerRendererInterface;
11
12
final class PanelLayer
13
{
14
    /** @var array<int, array<int, CellDataInterface>> */
15
    private array $data = [];
16
17
    /**
18
     * @param array<CellDataInterface> $array
19
     */
20 1
    public function __construct(array $array, private LayerRendererInterface $renderer)
21
    {
22 1
        foreach ($array as $data) {
23 1
            $this->data[$data->getPosX()][$data->getPosY()] = $data;
24
        }
25
    }
26
27 1
    public function renderCell(int $x, int $y, AbstractVisualPanel $panel): string
28
    {
29
        /**
30
         *
31
         if ($this->renderer instanceof SystemLayerRenderer) {
32
             // throw new RuntimeException(print_r($this->data, true));
33
         }
34
         */
35
36 1
        if (!array_key_exists($x, $this->data)) {
37
            throw new RuntimeException('array index not available');
38
        }
39
40 1
        return $this->renderer->render($this->data[$x][$y], $panel);
41
    }
42
}
43