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

ControllerDiscovery::getControllers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 10
rs 10
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