Test Failed
Pull Request — dev (#1952)
by Janko
02:59
created

ControllerDiscovery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 4

2 Methods

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