Locator::getProvidedDependency()   A
last analyzed

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 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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