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 Vincent
23:00
created

AnnotationParser   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 14
Bugs 1 Features 2
Metric Value
eloc 23
c 14
b 1
f 2
dl 0
loc 45
ccs 13
cts 13
cp 1
rs 10
wmc 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetadatas() 0 11 4
B getAnnotationReader() 0 26 7
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 Symfony\Component\Cache\Adapter\ApcuAdapter;
17
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
18
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
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)) {
43
                throw new ServiceNotFoundException("In order to use annotations, you need to install 'doctrine/annotations' first. See: 'https://www.doctrine-project.org/projects/annotations.html'");
44
            }
45 1
            if (!class_exists(ApcuAdapter::class)) {
46 1
                throw new ServiceNotFoundException("In order to use annotations, you need to install 'symfony/cache' first. See: 'https://symfony.com/doc/current/components/cache.html'");
47
            }
48
49 28
            if (class_exists(AnnotationRegistry::class)) {
50
                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

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