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

MapLayerRenderer::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Map\VisualPanel\Layer\Render;
6
7
use Stu\Component\Map\EncodedMapInterface;
8
use Stu\Lib\Map\VisualPanel\AbstractVisualPanel;
9
use Stu\Lib\Map\VisualPanel\Layer\Data\CellDataInterface;
10
use Stu\Lib\Map\VisualPanel\Layer\Data\MapData;
11
use Stu\Lib\Map\VisualPanel\Layer\PanelLayerEnum;
12
use Stu\Orm\Entity\LayerInterface;
13
14
final class MapLayerRenderer implements LayerRendererInterface
15
{
16
    private LayerInterface $layer;
17
18
    private EncodedMapInterface $encodedMap;
19
20 2
    public function __construct(LayerInterface $layer, EncodedMapInterface $encodedMap)
21
    {
22 2
        $this->layer = $layer;
23 2
        $this->encodedMap = $encodedMap;
24
    }
25
26
    /** @param MapData $data */
27 2
    public function render(CellDataInterface $data, AbstractVisualPanel $panel): string
28
    {
29 2
        return sprintf(
30 2
            '<img src="/assets/map/%s" style="z-index: %d; %s opacity:1;" />',
31 2
            $this->getMapGraphicPath($data),
32 2
            PanelLayerEnum::MAP->value,
33 2
            $panel->getHeightAndWidth()
34 2
        );
35
    }
36
37 2
    private function getMapGraphicPath(MapData $data): string
38
    {
39 2
        $layer = $this->layer;
40 2
        if ($layer->isEncoded()) {
41
42 1
            return $this->encodedMap->getEncodedMapPath(
43 1
                $data->getMapfieldType(),
44 1
                $layer
45 1
            );
46
        }
47
48 1
        return sprintf('%d/%d.png', $layer->getId(), $data->getMapfieldType());
49
    }
50
}
51