Passed
Push — master ( 55cfd1...cb4d54 )
by Nico
22:41
created

PanelLayer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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