Passed
Push — master ( f544cb...b3a3d9 )
by Nico
36:43 queued 09:10
created

ShowColonySandbox::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Admin\View\Sandbox;
6
7
use request;
8
use Stu\Component\Colony\ColonyMenuEnum;
9
use Stu\Lib\Colony\PlanetFieldHostProviderInterface;
10
use Stu\Lib\Colony\PlanetFieldHostTypeEnum;
11
use Stu\Module\Colony\Lib\ColonyGuiHelperInterface;
12
use Stu\Module\Control\GameControllerInterface;
13
use Stu\Module\Control\ViewControllerInterface;
14
use Stu\Orm\Repository\ColonySandboxRepositoryInterface;
15
16
final class ShowColonySandbox implements ViewControllerInterface
17
{
18
    public const VIEW_IDENTIFIER = 'SHOW_COLONY_SANDBOX';
19
20
    private ColonySandboxRepositoryInterface $colonySandboxRepository;
21
22
    private PlanetFieldHostProviderInterface $planetFieldHostProvider;
23
24
    private ColonyGuiHelperInterface $colonyGuiHelper;
25
26
    public function __construct(
27
        ColonySandboxRepositoryInterface $colonySandboxRepository,
28
        PlanetFieldHostProviderInterface $planetFieldHostProvider,
29
        ColonyGuiHelperInterface $colonyGuiHelper
30
    ) {
31
        $this->colonySandboxRepository = $colonySandboxRepository;
32
        $this->planetFieldHostProvider = $planetFieldHostProvider;
33
        $this->colonyGuiHelper = $colonyGuiHelper;
34
    }
35
36
    public function handle(GameControllerInterface $game): void
37
    {
38
        $game->setTemplateFile('html/admin/colonySandbox.twig');
39
        $game->setPageTitle(_('Kolonie-Sandbox'));
40
41
        $game->setTemplateVar('SANDBOXES', $this->colonySandboxRepository->getByUser($game->getUser()));
42
43
        $sandbox = $game->getViewContext()['HOST'] ?? null;
44
        if ($sandbox === null && request::has('id')) {
45
            $sandbox = $this->planetFieldHostProvider->loadHostViaRequestParameters($game->getUser());
46
        }
47
        $game->appendNavigationPart('/admin/?SHOW_COLONY_SANDBOX=1', _('Kolonie-Sandbox'));
48
49
        if ($sandbox !== null) {
50
            $game->appendNavigationPart(
51
                sprintf(
52
                    '/admin/?%s=1&id=%d&hosttype=%d',
53
                    static::VIEW_IDENTIFIER,
54
                    $sandbox->getId(),
55
                    PlanetFieldHostTypeEnum::SANDBOX->value
56
                ),
57
                $sandbox->getName()
58
            );
59
60
            $this->colonyGuiHelper->registerComponents($sandbox, $game);
61
62
            $game->setTemplateVar('HOST', $sandbox);
63
            $game->setTemplateVar('CURRENT_MENU', ColonyMenuEnum::MENU_INFO);
64
65
            $menu = ColonyMenuEnum::getFor($game->getViewContext()['COLONY_MENU'] ?? null);
66
67
            $game->setTemplateVar('SELECTED_COLONY_MENU_TEMPLATE', $menu->getTemplate());
68
        }
69
    }
70
}
71