Passed
Push — master ( ed4ed8...f8e53e )
by Patrick
03:11
created

Locator::getFacade()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ForecastAutomation\Kernel;
4
5
use ReflectionClass;
6
7
class Locator
8
{
9
    private array $callerClassParts;
10
11 2
    public function __construct(object $callerClass)
12
    {
13 2
        $this->callerClassParts = explode('\\', ltrim(get_class($callerClass), '\\'));
14 2
    }
15
16
    public function __call($name, $arguments)
17
    {
18
        // bla, bla testen
19
        echo "Rufe die Objektmethode '$name' "
20
            . implode(', ', $arguments). "\n";
21
    }
22
23
    public function getFacade(): object
24
    {
25
        return $this->resolve(KernelConfig::MODULE_FACADE);
26
    }
27
28
    public function getFactory(): object
29
    {
30
        return $this->resolve(KernelConfig::MODULE_FACTORY);
31
    }
32
33
    public function getProvidedDependency(string $id)
34
    {
35
        return $this->resolve(KernelConfig::MODULE_DEPENDENCY_PROVIDER)->get($id);
36
    }
37
38
    private function resolve(string $type): object
39
    {
40
        $reflector = new ReflectionClass(sprintf($type, $this->callerClassParts[KernelConfig::NAMESPACE_CLASSNAME_POSITION], $this->callerClassParts[KernelConfig::BUNDLE_CLASSNAME_POSITION], $this->callerClassParts[KernelConfig::BUNDLE_CLASSNAME_POSITION]));
41
        return $reflector->newInstance();
42
    }
43
}
44