Completed
Push — master ( 6198ec...5ffcc1 )
by Miloš
01:15
created

ReflectionResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConstructorParams() 0 23 4
1
<?php
2
3
namespace Laganica\Di\Resolver;
4
5
use Laganica\Di\Exception\ClassNotFoundException;
6
use ReflectionClass;
7
use ReflectionException;
8
9
/**
10
 * Class ReflectionResolver
11
 *
12
 * @package Laganica\Di\Resolver
13
 */
14
abstract class ReflectionResolver extends Resolver
15
{
16
    /**
17
     * @param string $class
18
     *
19
     * @throws ClassNotFoundException
20
     *
21
     * @return array
22
     */
23 11
    protected function getConstructorParams(string $class): array
24
    {
25 11
        $params = [];
26
27
        try {
28 11
            $reflection = new ReflectionClass($class);
29 2
        } catch (ReflectionException $e) {
30 2
            throw ClassNotFoundException::create($class);
31
        }
32
33 9
        $constructor = $reflection->getConstructor();
34
35 9
        if ($constructor === null) {
36 8
            return $params;
37
        }
38
39 4
        foreach ($constructor->getParameters() AS $param) {
40 4
            $dependencyId = $param->getClass()->name;
41 4
            $params[] = $this->getContainer()->get($dependencyId);
42
        }
43
44 3
        return $params;
45
    }
46
}
47