Passed
Pull Request — master (#1699)
by Nico
43:19 queued 18:45
created

StationProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Game\Lib\View\Provider;
6
7
use Stu\Component\Ship\SpacecraftTypeEnum;
8
use Stu\Module\Control\GameControllerInterface;
9
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface;
10
use Stu\Orm\Repository\ShipRepositoryInterface;
11
12
final class StationProvider implements ViewComponentProviderInterface
13
{
14
    private ShipRepositoryInterface $shipRepository;
15
16
    private ShipWrapperFactoryInterface $shipWrapperFactory;
17
18
    public function __construct(
19
        ShipRepositoryInterface $shipRepository,
20
        ShipWrapperFactoryInterface $shipWrapperFactory
21
    ) {
22
        $this->shipRepository = $shipRepository;
23
        $this->shipWrapperFactory = $shipWrapperFactory;
24
    }
25
26
    public function setTemplateVariables(GameControllerInterface $game): void
27
    {
28
        $userId = $game->getUser()->getId();
29
30
        $bases = $this->shipRepository->getByUserAndFleetAndType($userId, null, SpacecraftTypeEnum::SPACECRAFT_TYPE_STATION);
31
        $uplinkBases = $this->shipRepository->getByUplink($userId);
32
33
        $game->setTemplateVar(
34
            'BASES',
35
            $this->shipWrapperFactory->wrapShips(array_merge($bases, $uplinkBases))
36
        );
37
    }
38
}
39