AnnotationExtractor::getConstructorInjections()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 3
Bugs 2 Features 0
Metric Value
c 3
b 2
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
namespace mxdiModule\Service;
3
4
use Doctrine\Common\Annotations\AnnotationReader as Reader;
5
use mxdiModule\Annotation\AnnotationInterface;
6
7
class AnnotationExtractor implements ExtractorInterface
8
{
9
    /** @var Reader */
10
    protected $reader;
11
12 7
    public function __construct()
13
    {
14 7
        $this->reader = new Reader();
15 7
    }
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 2
    public function getConstructorInjections($fqcn)
21
    {
22 2
        if (! in_array('__construct', (array)get_class_methods($fqcn))) {
23 1
            return null;
24
        }
25
26 1
        return $this->reader->getMethodAnnotation(
27 1
            new \ReflectionMethod($fqcn, '__construct'),
28
            AnnotationInterface::class
29 1
        );
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 2 View Code Duplication
    public function getMethodsInjections($fqcn)
36
    {
37 2
        $injections = [];
38
39 2
        $reflection = new \ReflectionClass($fqcn);
40
41 2
        foreach ($reflection->getMethods() as $method) {
42 2
            $name = $method->getName();
43 2
            if ('__construct' === $name) {
44 1
                continue;
45
            }
46
47 1
            $inject = $this->reader->getMethodAnnotation(
48 1
                new \ReflectionMethod($fqcn, $name),
49
                AnnotationInterface::class
50 1
            );
51
52 1
            if (null !== $inject) {
53 1
                $injections[$name] = $inject;
54 1
            }
55 2
        }
56
57 2
        return $injections;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 1 View Code Duplication
    public function getPropertiesInjections($fqcn)
64
    {
65 1
        $injections = [];
66 1
        $reflection = new \ReflectionClass($fqcn);
67
68 1
        foreach ($reflection->getProperties() as $property) {
69 1
            $reflectionProperty = new \ReflectionProperty($fqcn, $property->getName());
70 1
            $inject = $this->reader->getPropertyAnnotation($reflectionProperty, AnnotationInterface::class);
71
72 1
            if (null !== $inject) {
73 1
                $injections[$property->getName()] = $inject;
74 1
            }
75 1
        }
76
77 1
        return $injections;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 1
    public function getChangeSet($fqcn)
84
    {
85 1
        return new ChangeSet($this, $fqcn);
86
    }
87
88
    /**
89
     * @param Reader $reader
90
     */
91 1
    public function setReader(Reader $reader)
92
    {
93 1
        $this->reader = $reader;
94 1
    }
95
}
96