Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#729)
by Timur
07:55
created

GraphClass   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 93.1%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 13
eloc 30
c 3
b 0
f 0
dl 0
loc 72
ccs 27
cts 29
cp 0.931
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAnnotationReader() 0 13 4
A getAnnotations() 0 11 4
A __construct() 0 16 4
A getPropertiesExtended() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Config\Parser\Annotation;
6
7
use Doctrine\Common\Annotations\AnnotationException;
8
use Doctrine\Common\Annotations\AnnotationReader;
9
use Doctrine\Common\Annotations\AnnotationRegistry;
10
use Overblog\GraphQLBundle\Annotation\Annotation;
11
use ReflectionClass;
12
use ReflectionException;
13
use ReflectionMethod;
14
use ReflectionProperty;
15
use Reflector;
16
use RuntimeException;
17
use function class_exists;
18
19
class GraphClass extends ReflectionClass
20
{
21
    private static ?AnnotationReader $annotationReader = null;
22
23
    protected array $annotations = [];
24
    protected array $propertiesExtended = [];
25
26
    /**
27
     * @param mixed $className
28
     *
29
     * @throws ReflectionException
30
     */
31 25
    public function __construct($className)
32
    {
33 25
        parent::__construct($className);
34
35 25
        $annotationReader = self::getAnnotationReader();
36 25
        $this->annotations = $annotationReader->getClassAnnotations($this);
37
38 25
        $reflection = $this;
39
        do {
40 25
            foreach ($reflection->getProperties() as $property) {
41 24
                if (isset($this->propertiesExtended[$property->getName()])) {
42 24
                    continue;
43
                }
44 24
                $this->propertiesExtended[$property->getName()] = $property;
45
            }
46 25
        } while ($reflection = $reflection->getParentClass());
47 25
    }
48
49
    /**
50
     * @return ReflectionProperty[]
51
     */
52 25
    public function getPropertiesExtended()
53
    {
54 25
        return $this->propertiesExtended;
55
    }
56
57
    /**
58
     * @phpstan-param ReflectionMethod|ReflectionProperty|null $from
59
     *
60
     * @return array<Annotation>
61
     *
62
     * @throws AnnotationException
63
     */
64 25
    public function getAnnotations(Reflector $from = null): array
65
    {
66
        switch (true) {
67 25
            case null === $from:
68 25
                return $this->annotations;
69 24
            case $from instanceof ReflectionMethod:
70 24
                return self::getAnnotationReader()->getMethodAnnotations($from);
71 24
            case $from instanceof ReflectionProperty:
72 24
                return self::getAnnotationReader()->getPropertyAnnotations($from);
73
            default:
74
                throw new AnnotationException(sprintf('Unable to retrieve annotations from object of class "%s".', get_class($from)));
75
        }
76
    }
77
78 25
    private static function getAnnotationReader(): AnnotationReader
79
    {
80 25
        if (null === self::$annotationReader) {
81 1
            if (!class_exists(AnnotationReader::class) ||
82 1
                !class_exists(AnnotationRegistry::class)) {
83
                throw new RuntimeException('In order to use graphql annotation, you need to require doctrine annotations');
84
            }
85
86 1
            AnnotationRegistry::registerLoader('class_exists');
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\Common\Annotati...istry::registerLoader() has been deprecated: This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. ( Ignorable by Annotation )

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

86
            /** @scrutinizer ignore-deprecated */ AnnotationRegistry::registerLoader('class_exists');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
87 1
            self::$annotationReader = new AnnotationReader();
88
        }
89
90 25
        return self::$annotationReader;
91
    }
92
}
93