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

Overview   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 31
ccs 0
cts 12
cp 0
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

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