Passed
Pull Request — master (#63)
by Mark
23:06
created

AttributeReaderAdapter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 21
dl 0
loc 58
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getPropertyAnnotations() 0 3 1
A getPropertyAnnotation() 0 10 2
A __construct() 0 3 1
A getMethodAnnotations() 0 3 1
A getMethodAnnotation() 0 10 2
A getClassAnnotations() 0 3 1
A getClassAnnotation() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Doctrine\Factory\MetadataReader;
6
7
use Doctrine\Common\Annotations\Reader;
8
use Doctrine\ORM\Mapping\Driver\AttributeReader;
9
use Doctrine\ORM\Mapping\Driver\RepeatableAttributeCollection;
10
use ReflectionClass;
11
use ReflectionMethod;
12
use ReflectionProperty;
13
14
final class AttributeReaderAdapter implements Reader
15
{
16
    private AttributeReader $attributeReader;
17
18
    public function __construct(AttributeReader $attributeReader)
19
    {
20
        $this->attributeReader = $attributeReader;
21
    }
22
23
    public function getClassAnnotations(ReflectionClass $class)
24
    {
25
        return $this->attributeReader->getClassAnnotations($class);
26
    }
27
28
    public function getClassAnnotation(ReflectionClass $class, $annotationName)
29
    {
30
        $result = $this->attributeReader->getClassAnnotation($class, $annotationName);
31
        if ($result instanceof RepeatableAttributeCollection) {
32
            $result = $result[0];
33
        }
34
35
        assert($result instanceof $annotationName);
36
37
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result also could return the type Doctrine\ORM\Mapping\Annotation which is incompatible with the return type mandated by Doctrine\Common\Annotati...r::getClassAnnotation() of Doctrine\Common\Annotations\T|null.
Loading history...
38
    }
39
40
    public function getMethodAnnotations(ReflectionMethod $method)
41
    {
42
        return $this->attributeReader->getMethodAnnotations($method);
43
    }
44
45
    public function getMethodAnnotation(ReflectionMethod $method, $annotationName)
46
    {
47
        $result = $this->attributeReader->getMethodAnnotation($method, $annotationName);
48
        if ($result instanceof RepeatableAttributeCollection) {
49
            $result = $result[0];
50
        }
51
52
        assert($result instanceof $annotationName);
53
54
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result also could return the type Doctrine\ORM\Mapping\Annotation which is incompatible with the return type mandated by Doctrine\Common\Annotati...::getMethodAnnotation() of Doctrine\Common\Annotations\T|null.
Loading history...
55
    }
56
57
    public function getPropertyAnnotations(ReflectionProperty $property)
58
    {
59
        return $this->attributeReader->getPropertyAnnotations($property);
60
    }
61
62
    public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
63
    {
64
        $result = $this->attributeReader->getPropertyAnnotation($property, $annotationName);
65
        if ($result instanceof RepeatableAttributeCollection) {
66
            $result = $result[0];
67
        }
68
69
        assert($result instanceof $annotationName);
70
71
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result also could return the type Doctrine\ORM\Mapping\Annotation which is incompatible with the return type mandated by Doctrine\Common\Annotati...getPropertyAnnotation() of Doctrine\Common\Annotations\T|null.
Loading history...
72
    }
73
}
74