Passed
Pull Request — master (#105)
by Evgeniy
08:08 queued 04:03
created

Reflection::getMethodDependencies()   A

Complexity

Conditions 6
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 8
nc 2
nop 1
dl 0
loc 12
ccs 9
cts 9
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI;
6
7
use ReflectionClass;
8
use ReflectionException;
9
10
class Reflection
11
{
12
    /**
13
     * @var Reflection\MethodService
14
     */
15
    private $reflectionMethod;
16
17 15
    public function __construct()
18
    {
19 15
        $this->reflectionMethod = new Reflection\MethodService();
20 15
    }
21
22
    /**
23
     * @param string $name
24
     * @return string[]
25
     * @internal
26
     */
27 12
    public function getDependencies(string $name): array
28
    {
29
        try {
30 12
            $class = new ReflectionClass($name);
31 9
            return $this->reflectionMethod->findDependencies($class->getConstructor());
32 3
        } catch (ReflectionException $exception) {
33 3
            return [];
34
        }
35
    }
36
37
    /**
38
     * @param string $name
39
     * @return bool
40
     * @internal
41
     */
42 3
    public function isInstantiable(string $name): bool
43
    {
44
        try {
45 3
            $class = new ReflectionClass($name);
46 3
            return $class->isInstantiable();
47 3
        } catch (ReflectionException $exception) {
48 3
            return false;
49
        }
50
    }
51
}
52