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

Overview::__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 1
Bugs 0 Features 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 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Game\View\Overview;
6
7
use request;
8
use Stu\Component\Game\ModuleViewEnum;
9
use Stu\Module\Control\GameControllerInterface;
10
use Stu\Module\Control\ViewControllerInterface;
11
use Stu\Module\Game\Lib\GameSetupInterface;
12
use Stu\Module\Game\Lib\View\ViewComponentLoaderInterface;
13
14
final class Overview implements ViewControllerInterface
15
{
16
    public const VIEW_IDENTIFIER = 'OVERVIEW';
17
18
    private ViewComponentLoaderInterface $viewComponentLoader;
19
20
    private GameSetupInterface $gameSetup;
21
22
    public function __construct(
23
        ViewComponentLoaderInterface $viewComponentLoader,
24
        GameSetupInterface $gameSetup
25
    ) {
26
        $this->viewComponentLoader = $viewComponentLoader;
27
        $this->gameSetup = $gameSetup;
28
    }
29
30
    public function handle(GameControllerInterface $game): void
31
    {
32
        $view = null;
33
        if (request::has('view')) {
34
            $view = ModuleViewEnum::tryFrom(request::getStringFatal('view'));
35
        }
36
37
        if ($view === null) {
38
            $view = $game->getViewContext()['VIEW'] ?? $game->getUser()->getDefaultView();
39
        }
40
        $game->setPageTitle($view->getTitle());
41
42
        /** @var ModuleViewEnum $view */
43
        $this->viewComponentLoader->registerViewComponents($view, $game);
44
        $this->gameSetup->setTemplateAndComponents($view->getTemplate(), $game);
45
    }
46
}
47