Test Failed
Push — dev ( 55bb00...c2c26e )
by Janko
17:14
created

OverviewTwig   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 28 4
A __construct() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\View\Overview;
6
7
use Stu\Component\Game\GameEnum;
8
use Stu\Component\Ship\SpacecraftTypeEnum;
9
use Stu\Lib\SessionInterface;
10
use Stu\Module\Control\GameControllerInterface;
11
use Stu\Module\Control\ViewControllerInterface;
12
use Stu\Module\Logging\LoggerEnum;
13
use Stu\Module\Logging\LoggerUtilFactoryInterface;
14
use Stu\Module\Logging\LoggerUtilInterface;
15
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface;
16
use Stu\Orm\Repository\FleetRepositoryInterface;
17
use Stu\Orm\Repository\ShipRepositoryInterface;
18
19
final class OverviewTwig implements ViewControllerInterface
20
{
21
    public const VIEW_IDENTIFIER = 'SHOW_SHIP_LIST_TWIG';
22
23
    private FleetRepositoryInterface $fleetRepository;
24
25
    private ShipRepositoryInterface $shipRepository;
26
27
    private ShipWrapperFactoryInterface $shipWrapperFactory;
28
29
    private SessionInterface $session;
30
31
    private LoggerUtilInterface $loggerUtil;
32
33
    public function __construct(
34
        FleetRepositoryInterface $fleetRepository,
35
        ShipRepositoryInterface $shipRepository,
36
        ShipWrapperFactoryInterface $shipWrapperFactory,
37
        SessionInterface $session,
38
        LoggerUtilFactoryInterface $loggerUtilFactory
39
    ) {
40
        $this->fleetRepository = $fleetRepository;
41
        $this->shipRepository = $shipRepository;
42
        $this->shipWrapperFactory = $shipWrapperFactory;
43
        $this->session = $session;
44
        $this->loggerUtil = $loggerUtilFactory->getLoggerUtil();
45
    }
46
47
    public function handle(GameControllerInterface $game): void
48
    {
49
        $userId = $game->getUser()->getId();
50
51
        $this->loggerUtil->init('stu', LoggerEnum::LEVEL_ERROR);
52
53
        $this->loggerUtil->log(sprintf('Shiplist-start, timestamp: %F', microtime(true)));
54
55
        $fleets = $this->fleetRepository->getByUser($userId);
56
        $ships = $this->shipRepository->getByUserAndFleetAndType($userId, null, SpacecraftTypeEnum::SPACECRAFT_TYPE_SHIP);
57
58
        foreach ($fleets as $fleet) {
59
            $fleet->setHiddenStyle($this->session->hasSessionValue('hiddenshiplistfleets', $fleet->getId()) ? 'display: none' : '');
60
        }
61
62
        $game->appendNavigationPart(
63
            'ship.php',
64
            _('Schiffe')
65
        );
66
        $game->setPageTitle(_('/ Schiffe'));
67
        $game->setTemplateFile('html/shiplist.twig', true);
68
69
        $game->setTemplateVar('MAX_CREW_PER_FLEET', GameEnum::CREW_PER_FLEET);
70
        $game->setTemplateVar('SHIPS_AVAILABLE', $fleets !== [] || $ships !== []);
71
        $game->setTemplateVar('FLEETWRAPPERS', $this->shipWrapperFactory->wrapFleets($fleets));
72
        $game->setTemplateVar('SINGLESHIPWRAPPERS', $this->shipWrapperFactory->wrapShips($ships));
73
74
        $this->loggerUtil->log(sprintf('Shiplist-end, timestamp: %F', microtime(true)));
75
    }
76
}
77