Passed
Push — master ( aa3b71...5e2219 )
by Nico
55:07 queued 26:20
created

Overview::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 1
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\ViewContextTypeEnum;
11
use Stu\Module\Control\ViewControllerInterface;
12
use Stu\Module\Game\Lib\View\ViewComponentLoaderInterface;
13
14
final class Overview implements ViewControllerInterface
15
{
16
    public const VIEW_IDENTIFIER = 'OVERVIEW';
17
18
    public function __construct(
19
        private ViewComponentLoaderInterface $viewComponentLoader,
20
    ) {
21
    }
22
23
    public function handle(GameControllerInterface $game): void
24
    {
25
        $moduleView = $this->getModuleView($game);
26
27
        $this->viewComponentLoader->registerViewComponents($moduleView, $game);
28
29
        $game->setPageTitle($moduleView->getTitle());
30
        $game->setViewTemplate($moduleView->getTemplate());
31
    }
32
33
    private function getModuleView(GameControllerInterface $game): ModuleViewEnum
34
    {
35
        $moduleView = null;
36
        if (request::has('view')) {
37
            $moduleView = ModuleViewEnum::tryFrom(request::getStringFatal('view'));
38
        }
39
40
        if ($moduleView !== null) {
41
            return $moduleView;
42
        }
43
44
        return $game->getViewContext(ViewContextTypeEnum::MODULE_VIEW) ?? $game->getUser()->getDefaultView();
45
    }
46
}
47