Locator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 18.75%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 36
ccs 3
cts 16
cp 0.1875
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 5 1
A getFactory() 0 3 1
A getFacade() 0 3 1
A getProvidedDependency() 0 3 1
A resolve() 0 5 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of forecast.it.fill project.
7
 * (c) Patrick Jaja <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace ForecastAutomation\Kernel;
13
14
use ReflectionClass;
15
16
class Locator
17
{
18
    private array $callerClassParts;
19
20 10
    public function __construct(object $callerClass)
21
    {
22 10
        $this->callerClassParts = explode('\\', ltrim(\get_class($callerClass), '\\'));
23 10
    }
24
25
    public function __call($name, $arguments): void
26
    {
27
        // bla, bla testen
28
        echo "Rufe die Objektmethode '{$name}' "
29
            .implode(', ', $arguments)."\n";
30
    }
31
32
    public function getFacade(): object
33
    {
34
        return $this->resolve(KernelConfig::MODULE_FACADE);
35
    }
36
37
    public function getFactory(): object
38
    {
39
        return $this->resolve(KernelConfig::MODULE_FACTORY);
40
    }
41
42
    public function getProvidedDependency(string $id)
43
    {
44
        return $this->resolve(KernelConfig::MODULE_DEPENDENCY_PROVIDER)->get($id);
45
    }
46
47
    private function resolve(string $type): object
48
    {
49
        $reflector = new ReflectionClass(sprintf($type, $this->callerClassParts[KernelConfig::NAMESPACE_CLASSNAME_POSITION], $this->callerClassParts[KernelConfig::BUNDLE_CLASSNAME_POSITION], $this->callerClassParts[KernelConfig::BUNDLE_CLASSNAME_POSITION]));
50
51
        return $reflector->newInstance();
52
    }
53
}
54