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

StationProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 24
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setTemplateVariables() 0 10 1
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