AnnotationResolver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Larapie\DataTransferObject\Resolvers;
4
5
use ReflectionProperty;
6
use Doctrine\Common\Annotations\AnnotationReader;
7
use Doctrine\Common\Annotations\AnnotationRegistry;
8
9
class AnnotationResolver
10
{
11
    /**
12
     * @var ReflectionProperty
13
     */
14
    protected $reflection;
15
16
    /** @var ?Reader */
0 ignored issues
show
Bug introduced by
The type Larapie\DataTransferObject\Resolvers\Reader was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
    protected static $reader;
18
19
    /**
20
     * TypeResolver constructor.
21
     * @param ReflectionProperty $reflection
22
     */
23 36
    public function __construct(ReflectionProperty $reflection)
24
    {
25 36
        $this->reflection = $reflection;
26 36
    }
27
28 36
    public function resolve(): array
29
    {
30 36
        $annotations = [];
31 36
        foreach (self::getReader()->getPropertyAnnotations($this->reflection) as $annotation) {
32 7
            $annotations[get_class($annotation)] = $annotation;
33
        }
34
35 36
        return $annotations;
36
    }
37
38 1
    public static function setReader()
39
    {
40
        //IMPLEMENTED LIKE THIS TO SUPPORT DOCTRINE\ANNOTATIONS v1.* & v2.*
41
42 1
        if (class_exists(AnnotationRegistry::class)) {
43 1
            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

43
            /** @scrutinizer ignore-deprecated */ 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...
44 1
            self::$reader = new AnnotationReader();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Annotations\AnnotationReader() of type Doctrine\Common\Annotations\AnnotationReader is incompatible with the declared type Larapie\DataTransferObject\Resolvers\Reader|null of property $reader.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
        } else {
46
            self::$reader = new \Doctrine\Annotations\AnnotationReader();
0 ignored issues
show
Bug introduced by
The type Doctrine\Annotations\AnnotationReader was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
47
        }
48 1
    }
49
50 36
    protected static function getReader()
51
    {
52 36
        if (self::$reader === null) {
53 1
            self::setReader();
54
        }
55
56 36
        return self::$reader;
57
    }
58
}
59