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 (#710)
by Vincent
25:24 queued 23:03
created

GraphClass   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 69
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 69
ccs 27
cts 29
cp 0.931
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAnnotationReader() 0 13 4
A getAnnotations() 0 15 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
    public function __construct(string $className)
25
    {
26 25
        parent::__construct($className);
27
28 25
        $annotationReader = self::getAnnotationReader();
29 25
        $this->annotations = $annotationReader->getClassAnnotations($this);
30
31 25
        $reflection = $this;
32
        do {
33 25
            foreach ($reflection->getProperties() as $property) {
34 24
                if (isset($this->propertiesExtended[$property->getName()])) {
35 24
                    continue;
36
                }
37 24
                $this->propertiesExtended[$property->getName()] = $property;
38
            }
39 25
        } while ($reflection = $reflection->getParentClass());
40 25
    }
41
42
    /**
43
     * @return ReflectionProperty[]
44
     */
45 25
    public function getPropertiesExtended()
46
    {
47 25
        return $this->propertiesExtended;
48
    }
49
50
    /**
51
     * @param ReflectionMethod|ReflectionProperty|null $from
52
     *
53
     * @return array
54
     */
55 25
    public function getAnnotations(object $from = null)
56
    {
57 25
        if (!$from) {
58 25
            return $this->annotations;
59
        }
60
61 24
        if ($from instanceof ReflectionMethod) {
62 24
            return self::getAnnotationReader()->getMethodAnnotations($from);
63
        }
64
65 24
        if ($from instanceof ReflectionProperty) {
66 24
            return self::getAnnotationReader()->getPropertyAnnotations($from);
67
        }
68
69
        throw new AnnotationException(sprintf('Unable to retrieve annotations from object of class "%s".', get_class($from)));
70
    }
71
72 25
    private static function getAnnotationReader(): AnnotationReader
73
    {
74 25
        if (null === self::$annotationReader) {
75 1
            if (!class_exists(AnnotationReader::class) ||
76 1
                !class_exists(AnnotationRegistry::class)) {
77
                throw new RuntimeException('In order to use graphql annotation, you need to require doctrine annotations');
78
            }
79
80 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

80
            /** @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...
81 1
            self::$annotationReader = new AnnotationReader();
82
        }
83
84 25
        return self::$annotationReader;
85
    }
86
}
87