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

InjectionPoint   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.59%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 72
ccs 25
cts 27
cp 0.9259
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getParameter() 0 4 1
A getMethod() 0 10 2
A getClass() 0 8 2
A getQualifiers() 0 16 3
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