Passed
Push — master ( 6d626d...5de675 )
by Janko
09:20
created

LssBlockadeGridFactory::getBlockedCoords()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 6
nc 2
nop 1
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Map\VisualPanel\LssBlockade;
6
7
use Stu\Lib\Map\FieldTypeEffectEnum;
8
use Stu\Lib\Map\VisualPanel\AbstractVisualPanel;
9
use Stu\Lib\Map\VisualPanel\PanelBoundaries;
10
use Stu\Orm\Entity\Location;
11
use Stu\Orm\Repository\MapRepositoryInterface;
12
use Stu\Orm\Repository\StarSystemMapRepositoryInterface;
13
14
class LssBlockadeGridFactory
15
{
16 2
    public function __construct(
17
        private readonly MapRepositoryInterface $mapRepository,
18
        private readonly StarSystemMapRepositoryInterface $starSystemMapRepository
19 2
    ) {}
20
21 5
    public function createLssBlockadeGrid(Location $observerLocation, AbstractVisualPanel $panel): LssBlockadeGrid
22
    {
23 5
        $boundaries = $panel->getBoundaries();
24
25 5
        $blockadeGrid = new LssBlockadeGrid(
26 5
            $boundaries->getMinX(),
27 5
            $boundaries->getMaxX(),
28 5
            $boundaries->getMinY(),
29 5
            $boundaries->getMaxY(),
30 5
            $observerLocation->getX(),
31 5
            $observerLocation->getY()
32 5
        );
33
34 5
        $blockedLocations = $this->getBlockedCoords($boundaries);
35
36 5
        array_walk(
37 5
            $blockedLocations,
38 5
            function (array $entry) use ($blockadeGrid): void {
39 1
                $blockadeGrid->setBlocked($entry['x'], $entry['y']);
40 5
            }
41 5
        );
42
43 5
        return $blockadeGrid;
44
    }
45
46
    /** @return array< array{x: int, y: int, effects: ?string}> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array< at position 2 could not be parsed: the token is null at position 2.
Loading history...
47 5
    private function getBlockedCoords(PanelBoundaries $boundaries): array
48
    {
49 5
        $locations = $boundaries->isOnMap()
50 1
            ? $this->mapRepository->getLssBlockadeLocations($boundaries)
51 4
            : $this->starSystemMapRepository->getLssBlockadeLocations($boundaries);
52
53 5
        return array_filter(
54 5
            $locations,
55 5
            fn(array $entry): bool => $entry['effects'] !== null && str_contains($entry['effects'], FieldTypeEffectEnum::LSS_BLOCKADE->value)
56 5
        );
57
    }
58
}
59