Completed
Push — master ( d10f54...00ced4 )
by
unknown
05:32
created

AnnotationPropertyAnalyzer::analyze()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.2
c 0
b 0
f 0
ccs 8
cts 8
cp 1
cc 4
eloc 11
nc 6
nop 4
crap 4
1
<?php declare(strict_types=1);
0 ignored issues
show
Coding Style introduced by
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
/**
3
 * Created by Ruslan Molodyko.
4
 * Date: 10.09.2016
5
 * Time: 17:48
6
 */
7
namespace samsonframework\container\definition\analyzer\annotation;
8
9
use samsonframework\container\definition\analyzer\DefinitionAnalyzer;
10
use samsonframework\container\definition\analyzer\PropertyAnalyzerInterface;
11
use samsonframework\container\definition\ClassDefinition;
12
use samsonframework\container\definition\exception\PropertyDefinitionAlreadyExistsException;
13
use samsonframework\container\definition\PropertyDefinition;
14
15
class AnnotationPropertyAnalyzer extends AbstractAnnotationAnalyzer implements PropertyAnalyzerInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     * @throws PropertyDefinitionAlreadyExistsException
20
     */
21 2
    public function analyze(
22
        DefinitionAnalyzer $analyzer,
23
        \ReflectionProperty $reflectionProperty,
24
        ClassDefinition $classDefinition,
25
        PropertyDefinition $propertyDefinition = null
26
    ) {
27
        // Define property if not exists
28 2
        if (!$propertyDefinition) {
29 2
            $propertyDefinition = $classDefinition->defineProperty($reflectionProperty->getName());
30
        }
31
        // Resolve annotations
32 2
        $annotations = $this->reader->getPropertyAnnotations($reflectionProperty);
33 2
        foreach ($annotations as $annotation) {
34 2
            if ($annotation instanceof ResolvePropertyInterface) {
35 2
                $annotation->resolveProperty($analyzer, $reflectionProperty, $classDefinition, $propertyDefinition);
0 ignored issues
show
Compatibility introduced by
$propertyDefinition of type object<samsonframework\c...opertyBuilderInterface> is not a sub-type of object<samsonframework\c...ion\PropertyDefinition>. It seems like you assume a concrete implementation of the interface samsonframework\containe...ropertyBuilderInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
36
            }
37
        }
38 2
    }
39
}
40