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

Passed
Pull Request — master (#801)
by Timur
20:26
created

GraphClass   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
c 0
b 0
f 0
dl 0
loc 74
rs 10
wmc 13

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetadatas() 0 13 4
A getPropertiesExtended() 0 3 1
A getAnnotationReader() 0 13 4
A __construct() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Config\Parser\ClassParser;
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
    public function __construct($className)
32
    {
33
        parent::__construct($className);
34
35
        $annotationReader = self::getAnnotationReader();
36
        $this->annotations = $annotationReader->getClassAnnotations($this);
37
38
        $reflection = $this;
39
        do {
40
            foreach ($reflection->getProperties() as $property) {
41
                if (isset($this->propertiesExtended[$property->getName()])) {
42
                    continue;
43
                }
44
                $this->propertiesExtended[$property->getName()] = $property;
45
            }
46
        } while ($reflection = $reflection->getParentClass());
47
    }
48
49
    /**
50
     * @return ReflectionProperty[]
51
     */
52
    public function getPropertiesExtended()
53
    {
54
        return $this->propertiesExtended;
55
    }
56
57
    /**
58
     * @phpstan-param ReflectionMethod|ReflectionProperty|null $from
59
     *
60
     * @return array<Annotation>
61
     *
62
     * @throws AnnotationException
63
     */
64
    public function getMetadatas(Reflector $from = null): array
65
    {
66
        switch (true) {
67
            case null === $from:
68
                return $this->annotations;
69
            case $from instanceof ReflectionMethod:
70
                // @phpstan-ignore-next-line
71
                return self::getAnnotationReader()->getMethodAnnotations($from);
72
            case $from instanceof ReflectionProperty:
73
                // @phpstan-ignore-next-line
74
                return self::getAnnotationReader()->getPropertyAnnotations($from);
75
            default:
76
                throw new AnnotationException(sprintf('Unable to retrieve annotations from object of class "%s".', get_class($from)));
77
        }
78
    }
79
80
    private static function getAnnotationReader(): AnnotationReader
81
    {
82
        if (null === self::$annotationReader) {
83
            if (!class_exists(AnnotationReader::class) ||
84
                !class_exists(AnnotationRegistry::class)) {
85
                throw new RuntimeException('In order to use graphql annotation, you need to require doctrine annotations');
86
            }
87
88
            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

88
            /** @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...
89
            self::$annotationReader = new AnnotationReader();
90
        }
91
92
        return self::$annotationReader;
93
    }
94
}
95