Completed
Push — master ( 00ced4...d3edd8 )
by
unknown
07:54
created

AnnotationPropertyAnalyzer::analyze()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 8.7624
c 0
b 0
f 0
cc 5
eloc 12
nc 7
nop 3
crap 5
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\exception\PropertyDefinitionNotFoundException;
14
15
class AnnotationPropertyAnalyzer extends AbstractAnnotationAnalyzer implements PropertyAnalyzerInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     * @throws PropertyDefinitionAlreadyExistsException
20
     * @throws PropertyDefinitionNotFoundException
21
     */
22 2
    public function analyze(
23
        DefinitionAnalyzer $analyzer,
24
        ClassDefinition $classDefinition,
25
        \ReflectionProperty $reflectionProperty
26
    ) {
27 2
        $propertyName = $reflectionProperty->getName();
28
        // Resolve annotations
29 2
        $annotations = $this->reader->getPropertyAnnotations($reflectionProperty);
30 2
        if (count($annotations)) {
31
            // Define property if not exists
32 2
            if (!$classDefinition->hasProperty($propertyName)) {
33 2
                $classDefinition->defineProperty($propertyName);
34
            }
35
            // Exec annotations
36 2
            foreach ($annotations as $annotation) {
37 2
                if ($annotation instanceof ResolvePropertyInterface) {
38 2
                    $annotation->resolveProperty($analyzer, $classDefinition, $reflectionProperty);
39
                }
40
            }
41
        }
42 2
    }
43
}
44