Passed
Push — master ( 6b02b9...a180a6 )
by Nico
26:39 queued 18:43
created

EncodedMap   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getEncodedMapPath() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Map;
6
7
use RuntimeException;
8
use Stu\Module\Config\StuConfigInterface;
9
use Stu\Orm\Entity\LayerInterface;
10
11
class EncodedMap implements EncodedMapInterface
12
{
13
    private StuConfigInterface $stuConfig;
14
15 2
    public function __construct(StuConfigInterface $stuConfig)
16
    {
17 2
        $this->stuConfig = $stuConfig;
18
    }
19
20 2
    public function getEncodedMapPath(int $mapFieldType, LayerInterface $layer): string
21
    {
22 2
        $key = $this->stuConfig->getGameSettings()->getMapSettings()->getEncryptionKey();
23 2
        if ($key === null) {
24 1
            throw new RuntimeException('encoding key is missing in configuration');
25
        }
26
27 1
        $cipher = base64_encode(crypt((string)$mapFieldType, $key));
28 1
        $cipher = str_replace('/', '5', $cipher);
29
30 1
        return sprintf(
31 1
            '%d/encoded/%s.png',
32 1
            $layer->getId(),
33 1
            implode("/", str_split($cipher, 8))
0 ignored issues
show
Bug introduced by
It seems like str_split($cipher, 8) can also be of type true; however, parameter $pieces of implode() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
            implode("/", /** @scrutinizer ignore-type */ str_split($cipher, 8))
Loading history...
34 1
        );
35
    }
36
}
37