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

UserYRow   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 42.42%

Importance

Changes 0
Metric Value
eloc 33
c 0
b 0
f 0
dl 0
loc 66
ccs 14
cts 33
cp 0.4242
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 25 1
A getFields() 0 29 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Starmap\Lib;
6
7
use RuntimeException;
8
use Stu\Component\Map\EncodedMapInterface;
9
use Stu\Orm\Entity\LayerInterface;
10
use Stu\Orm\Entity\UserInterface;
11
use Stu\Orm\Repository\MapRepositoryInterface;
12
use Stu\Orm\Repository\StarSystemMapRepositoryInterface;
13
14
class UserYRow extends YRow
15
{
16
    private UserInterface $user;
17
18
    private MapRepositoryInterface $mapRepository;
19
    private StarmapUiFactoryInterface $starmapUiFactory;
20
21 1
    public function __construct(
22
        StarmapUiFactoryInterface $starmapUiFactory,
23
        MapRepositoryInterface $mapRepository,
24
        StarSystemMapRepositoryInterface $starSystemMapRepository,
25
        EncodedMapInterface $encodedMap,
26
        UserInterface $user,
27
        LayerInterface $layer,
28
        int $cury,
29
        int $minx,
30
        int $maxx,
31
        int $systemId = 0
32
    ) {
33 1
        parent::__construct(
34 1
            $mapRepository,
35 1
            $starSystemMapRepository,
36 1
            $encodedMap,
37 1
            $layer,
38 1
            $cury,
39 1
            $minx,
40 1
            $maxx,
41 1
            $systemId
42 1
        );
43 1
        $this->user = $user;
44 1
        $this->mapRepository = $mapRepository;
45 1
        $this->starmapUiFactory = $starmapUiFactory;
46
    }
47
48
    /**
49
     * @return array<ExplorableStarMapItemInterface>
50
     */
51
    public function getFields(): array
52
    {
53
        $layer = $this->layer;
54
        if ($layer === null) {
55
            throw new RuntimeException('this should not happen');
56
        }
57
58
        $maps = $this->mapRepository->getExplored(
59
            $this->user->getId(),
60
            $layer->getId(),
61
            $this->minx,
62
            $this->maxx,
63
            $this->row
64
        );
65
        $hasExploredLayer = $this->user->hasExplored($layer->getId());
66
67
        $result = [];
68
69
        foreach ($maps as $item) {
70
71
            $starmapItem = $this->starmapUiFactory->createExplorableStarmapItem($item, $layer);
72
            if (!$hasExploredLayer && $item->getUserId() === null) {
73
                $starmapItem->setHide(true);
74
            }
75
76
            $result[$item->getCx()] = $starmapItem;
77
        }
78
79
        return $result;
80
    }
81
}
82