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 (#730)
by Mathieu
23:10 queued 20:42
created

GraphClass::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 10
c 3
b 0
f 0
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.9332
cc 4
nc 3
nop 1
crap 4
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 ReflectionClass;
11
use ReflectionMethod;
12
use ReflectionProperty;
13
use RuntimeException;
14
use function class_exists;
15
16
class GraphClass extends ReflectionClass
17
{
18
    private static ?AnnotationReader $annotationReader = null;
19
20
    protected array $annotations = [];
21
22
    protected array $propertiesExtended = [];
23
24
    /**
25
     * @param mixed $className
26
     */
27 25
    public function __construct($className)
28
    {
29 25
        parent::__construct($className);
30
31 25
        $annotationReader = self::getAnnotationReader();
32 25
        $this->annotations = $annotationReader->getClassAnnotations($this);
33
34 25
        $reflection = $this;
35
        do {
36 25
            foreach ($reflection->getProperties() as $property) {
37 24
                if (isset($this->propertiesExtended[$property->getName()])) {
38 24
                    continue;
39
                }
40 24
                $this->propertiesExtended[$property->getName()] = $property;
41
            }
42 25
        } while ($reflection = $reflection->getParentClass());
43 25
    }
44
45
    /**
46
     * @return ReflectionProperty[]
47
     */
48 25
    public function getPropertiesExtended()
49
    {
50 25
        return $this->propertiesExtended;
51
    }
52
53
    /**
54
     * @param ReflectionMethod|ReflectionProperty|null $from
55
     *
56
     * @return array
57
     */
58 25
    public function getAnnotations(object $from = null)
59
    {
60 25
        if (!$from) {
61 25
            return $this->annotations;
62
        }
63
64 24
        if ($from instanceof ReflectionMethod) {
65 24
            return self::getAnnotationReader()->getMethodAnnotations($from);
66
        }
67
68 24
        if ($from instanceof ReflectionProperty) {
69 24
            return self::getAnnotationReader()->getPropertyAnnotations($from);
70
        }
71
72
        /** @phpstan-ignore-next-line */
73
        throw new AnnotationException(sprintf('Unable to retrieve annotations from object of class "%s".', get_class($from)));
74
    }
75
76 25
    private static function getAnnotationReader(): AnnotationReader
77
    {
78 25
        if (null === self::$annotationReader) {
79 1
            if (!class_exists(AnnotationReader::class) ||
80 1
                !class_exists(AnnotationRegistry::class)) {
81
                throw new RuntimeException('In order to use graphql annotation, you need to require doctrine annotations');
82
            }
83
84 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

84
            /** @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...
85 1
            self::$annotationReader = new AnnotationReader();
86
        }
87
88 25
        return self::$annotationReader;
89
    }
90
}
91