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

EncodedMap::getEncodedMapPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

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