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

MapLayerRenderer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getMapGraphicPath() 0 12 2
A render() 0 7 1
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