Completed
Push — 2.x ( 590aac...5c2340 )
by Akihito
07:34 queued 03:49
created

InjectionPoint::getMethod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0185
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the Ray.Di package.
6
 *
7
 * @license http://opensource.org/licenses/MIT MIT
8
 */
9
namespace Ray\Di;
10
11
use Doctrine\Common\Annotations\Reader;
12
use Ray\Di\Di\Qualifier;
13
14
final class InjectionPoint implements InjectionPointInterface
15
{
16
    /**
17
     * @var \ReflectionParameter
18
     */
19
    private $parameter;
20
21
    /**
22
     * @var Reader
23
     */
24
    private $reader;
25
26 42
    public function __construct(\ReflectionParameter $parameter, Reader $reader)
27
    {
28 42
        $this->parameter = $parameter;
29 42
        $this->reader = $reader;
30 42
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 2
    public function getParameter() : \ReflectionParameter
36
    {
37 2
        return $this->parameter;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 3
    public function getMethod() : \ReflectionMethod
44
    {
45 3
        $class = $this->parameter->getDeclaringClass();
46 3
        if (! $class instanceof \ReflectionClass) {
47
            throw new \LogicException($this->parameter->getName());
0 ignored issues
show
Bug introduced by
Consider using $this->parameter->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
48
        }
49 3
        $method = $this->parameter->getDeclaringFunction()->getShortName();
50
51 3
        return new \ReflectionMethod($class->name, $method);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 1
    public function getClass() : \ReflectionClass
58
    {
59 1
        $class = $this->parameter->getDeclaringClass();
60 1
        if ($class instanceof \ReflectionClass) {
61 1
            return $class;
62
        }
63
        throw new \LogicException($this->parameter->getName());
0 ignored issues
show
Bug introduced by
Consider using $this->parameter->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 2
    public function getQualifiers() : array
70
    {
71 2
        $qualifiers = [];
72 2
        $annotations = $this->reader->getMethodAnnotations($this->getMethod());
73 2
        foreach ($annotations as $annotation) {
74 2
            $qualifier = $this->reader->getClassAnnotation(
75 2
                new \ReflectionClass($annotation),
76 2
                Qualifier::class
77
            );
78 2
            if ($qualifier instanceof Qualifier) {
79 2
                $qualifiers[] = $annotation;
80
            }
81
        }
82
83 2
        return $qualifiers;
84
    }
85
}
86