Reflection::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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