AnnotationExtractor   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 89
Duplicated Lines 44.94 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 11
Bugs 4 Features 0
Metric Value
c 11
b 4
f 0
dl 40
loc 89
wmc 12
lcom 1
cbo 2
ccs 40
cts 40
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getChangeSet() 0 4 1
A setReader() 0 4 1
A getConstructorInjections() 0 11 2
B getMethodsInjections() 24 24 4
A getPropertiesInjections() 16 16 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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