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 (#867)
by
unknown
44:03 queued 19:05
created

AnnotationParser   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 12
Bugs 1 Features 0
Metric Value
eloc 21
c 12
b 1
f 0
dl 0
loc 44
ccs 13
cts 13
cp 1
rs 10
wmc 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getAnnotationReader() 0 25 7
A getMetadatas() 0 11 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Config\Parser;
6
7
use Doctrine\Common\Annotations\AnnotationReader;
8
use Doctrine\Common\Annotations\AnnotationRegistry;
9
use Doctrine\Common\Annotations\PsrCachedReader;
10
use Doctrine\Common\Annotations\Reader;
11
use Overblog\GraphQLBundle\Config\Parser\MetadataParser\MetadataParser;
12
use ReflectionClass;
13
use ReflectionMethod;
14
use ReflectionProperty;
15
use Reflector;
16
use RuntimeException;
17
use Symfony\Component\Cache\Adapter\ApcuAdapter;
18
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
19
20
class AnnotationParser extends MetadataParser
21
{
22 28
    public const METADATA_FORMAT = '@%s';
23
24 28
    protected static Reader $annotationReader;
25
26
    protected static function getMetadatas(Reflector $reflector): array
27 28
    {
28 27
        $reader = self::getAnnotationReader();
29 27
30
        switch (true) {
31
            case $reflector instanceof ReflectionClass: return $reader->getClassAnnotations($reflector);
32 27
            case $reflector instanceof ReflectionMethod: return $reader->getMethodAnnotations($reflector);
33
            case $reflector instanceof ReflectionProperty: return $reader->getPropertyAnnotations($reflector);
34
        }
35 28
36
        return [];
37 28
    }
38 1
39 1
    protected static function getAnnotationReader(): Reader
40
    {
41
        if (!isset(self::$annotationReader)) {
42
            if (!class_exists(AnnotationReader::class) || !class_exists(AnnotationRegistry::class)) {
43
                // @codeCoverageIgnoreStart
44
                throw new RuntimeException("In order to use annotations, you need to install 'doctrine/annotations' first. See: 'https://www.doctrine-project.org/projects/annotations.html'");
45 1
                // @codeCoverageIgnoreEnd
46 1
            }
47
48
            if (class_exists(AnnotationRegistry::class)) {
49 28
                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

49
                /** @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...
50
            }
51
            $cacheKey = md5(__DIR__);
52
            // @codeCoverageIgnoreStart
53
            if (extension_loaded('apcu') && apcu_enabled()) {
54
                $annotationCache = new ApcuAdapter($cacheKey);
55
            } else {
56
                $annotationCache = new PhpFilesAdapter($cacheKey);
57
            }
58
            // @codeCoverageIgnoreEnd
59
60
            self::$annotationReader = new PsrCachedReader(new AnnotationReader(), $annotationCache, true);
61
        }
62
63
        return self::$annotationReader;
64
    }
65
}
66