Completed
Pull Request — master (#1)
by Jim
16:46 queued 06:45
created

Reflector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 43
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getNameForClass() 0 9 2
A loadAnnotation() 0 9 1
1
<?php
2
3
4
namespace Jarobe\TaskRunner\Hydrator;
5
6
use Doctrine\Common\Annotations\Reader;
7
use Jarobe\TaskRunner\Annotation\TaskType as TaskTypeAnnotation;
8
9
class Reflector
10
{
11
    /**
12
     * @var Reader
13
     */
14
    private $annotationReader;
15
16
    /**
17
     * @param Reader $annotationReader
18
     */
19
    public function __construct(Reader $annotationReader)
20
    {
21
        $this->annotationReader = $annotationReader;
22
    }
23
24
    /**
25
     * @param $class
26
     * @return null
27
     */
28
    public function getNameForClass($class)
29
    {
30
        $annotation = $this->loadAnnotation($class);
31
32
        if (!$annotation) {
33
            return null;
34
        }
35
        return $annotation->name;
36
    }
37
38
    /**
39
     * @param $class
40
     * @return TaskTypeAnnotation|null
41
     */
42
    protected function loadAnnotation($class)
43
    {
44
        $annotationClass = TaskTypeAnnotation::class;
45
46
        $classReflection = new \ReflectionClass($class);
47
        /** @var TaskTypeAnnotation $annotation */
48
        $annotation = $this->annotationReader->getClassAnnotation($classReflection, $annotationClass);
49
        return $annotation;
50
    }
51
}