Failed Conditions
Pull Request — master (#63)
by Adrien
14:14
created

AttributeReaderAdapter::getMethodAnnotations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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);
0 ignored issues
show
Bug introduced by
The method getClassAnnotation() does not exist on Doctrine\ORM\Mapping\Driver\AttributeReader. Did you maybe mean getClassAnnotations()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        /** @scrutinizer ignore-call */ 
31
        $result = $this->attributeReader->getClassAnnotation($class, $annotationName);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
        if ($result instanceof RepeatableAttributeCollection) {
32
            $result = $result[0];
33
        }
34
35
        assert($result instanceof $annotationName);
36
37
        return $result;
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);
0 ignored issues
show
Bug introduced by
The method getMethodAnnotation() does not exist on Doctrine\ORM\Mapping\Driver\AttributeReader. Did you maybe mean getMethodAnnotations()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        /** @scrutinizer ignore-call */ 
48
        $result = $this->attributeReader->getMethodAnnotation($method, $annotationName);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
        if ($result instanceof RepeatableAttributeCollection) {
49
            $result = $result[0];
50
        }
51
52
        assert($result instanceof $annotationName);
53
54
        return $result;
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;
72
    }
73
}
74