Passed
Push — dev ( 219c54...831a1f )
by Janko
08:28
created

ControllerDiscovery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 23
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getControllers() 0 10 2
A getContainerIdentifier() 0 6 2
1
<?php
2
3
namespace Stu\Module\Control\Component;
4
5
use Stu\Component\Game\ModuleEnum;
6
use Stu\Config\Init;
7
use Stu\Module\Control\ControllerInterface;
8
9
class ControllerDiscovery implements ControllerDiscoveryInterface
10
{
11
    /**
12
     * @return array<string, ControllerInterface>
13
     */
14
    public function getControllers(ModuleEnum $module, bool $isViewController): array
15
    {
16
        $controllers = Init::getContainer()->get($this->getContainerIdentifier($module->name, $isViewController));
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Stu\Component\Game\ModuleEnum.
Loading history...
17
18
        $commonModule = $module->getCommonModule();
19
        if ($commonModule === null) {
20
            return $controllers;
21
        }
22
23
        return array_merge(Init::getContainer()->get($this->getContainerIdentifier($commonModule, $isViewController)), $controllers);
24
    }
25
26
    private function getContainerIdentifier(string $module, bool $isViewController): string
27
    {
28
        return sprintf(
29
            '%s_%s',
30
            $module,
31
            $isViewController ? 'VIEWS' : 'ACTIONS'
32
        );
33
    }
34
}
35