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   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 93.1%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAnnotationReader() 0 13 4
A getAnnotations() 0 16 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 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