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

UserYRow::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 12
c 0
b 0
f 0
nc 1
nop 10
dl 0
loc 25
ccs 14
cts 14
cp 1
crap 1
rs 9.8666

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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