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

ViewComponentLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 30
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A registerViewComponents() 0 18 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Game\Lib\View;
6
7
use RuntimeException;
8
use Stu\Component\Game\ModuleViewEnum;
9
use Stu\Module\Control\GameControllerInterface;
10
use Stu\Module\Game\Lib\View\Provider\ViewComponentProviderInterface;
11
12
final class ViewComponentLoader implements ViewComponentLoaderInterface
13
{
14
    /** @var array<int, ViewComponentProviderInterface> */
15
    private array $viewComponentProviders;
16
17
    /** @param array<int, ViewComponentProviderInterface> $viewComponentProviders */
18 2
    public function __construct(
19
        array $viewComponentProviders
20
    ) {
21 2
        $this->viewComponentProviders = $viewComponentProviders;
22
    }
23
24 2
    public function registerViewComponents(
25
        ModuleViewEnum $view,
26
        GameControllerInterface $game
27
    ): void {
28
29 2
        if (!array_key_exists($view->value, $this->viewComponentProviders)) {
30 1
            throw new RuntimeException(sprintf('viewComponentProvider with follwing id does not exist: %s', $view->value));
31
        }
32
33 1
        $game->appendNavigationPart(
34 1
            $view->getPhpPage(),
35 1
            $view->getTitle(),
36 1
        );
37
38 1
        $componentProvider = $this->viewComponentProviders[$view->value];
39 1
        $componentProvider->setTemplateVariables($game);
40
41 1
        $game->setTemplateVar('CURRENT_VIEW', $view);
42
    }
43
}
44