Passed
Push — master ( 0756fe...706dc7 )
by Arthur
14:47
created

AnnotationResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 13
dl 0
loc 42
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setReader() 0 4 1
A getReader() 0 7 2
A resolve() 0 7 2
1
<?php
2
3
4
namespace Larapie\DataTransferObject\Resolvers;
5
6
7
use Doctrine\Common\Annotations\AnnotationReader;
8
use Doctrine\Common\Annotations\CachedReader;
9
use Doctrine\Common\Annotations\Reader;
10
use Doctrine\Common\Cache\ArrayCache;
11
use ReflectionProperty;
12
13
class AnnotationResolver
14
{
15
16
    /**
17
     * @var ReflectionProperty
18
     */
19
    protected $reflection;
20
21
    /** @var ?Reader */
22
    protected static $reader;
23
24
    /**
25
     * TypeResolver constructor.
26
     * @param ReflectionProperty $reflection
27
     */
28
    public function __construct(ReflectionProperty $reflection)
29
    {
30
        $this->reflection = $reflection;
31
    }
32
33
    public function resolve() : array
34
    {
35
        $annotations = [];
36
        foreach (self::getReader()->getPropertyAnnotations($this->reflection) as $annotation) {
37
            $annotations[get_class($annotation)] = $annotation;
38
        }
39
        return $annotations;
40
    }
41
42
    public static function setReader(Reader $reader)
43
    {
44
        \Doctrine\Common\Annotations\AnnotationRegistry::registerUniqueLoader('class_exists');
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\Common\Annotati...:registerUniqueLoader() has been deprecated: this method is deprecated and will be removed in doctrine/annotations 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

44
        /** @scrutinizer ignore-deprecated */ \Doctrine\Common\Annotations\AnnotationRegistry::registerUniqueLoader('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...
45
        self::$reader = $reader;
46
    }
47
48
    protected static function getReader(): Reader
49
    {
50
        if (self::$reader === null) {
51
            self::setReader(new CachedReader(new AnnotationReader(), new ArrayCache()));
52
        }
53
54
        return self::$reader;
55
    }
56
57
}