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

PanelLayer::renderCell()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 3
dl 0
loc 14
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 1
b 0
f 0
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