AnnotationPropertyAnalyzer::analyze()   B
last analyzed

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
/**
16
 * Class AnnotationPropertyAnalyzer
17
 *
18
 * @author Ruslan Molodyko <[email protected]>
19
 */
20
class AnnotationPropertyAnalyzer extends AbstractAnnotationAnalyzer implements PropertyAnalyzerInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     * @throws PropertyDefinitionAlreadyExistsException
25
     * @throws PropertyDefinitionNotFoundException
26
     */
27 2
    public function analyze(
28
        DefinitionAnalyzer $analyzer,
29
        ClassDefinition $classDefinition,
30
        \ReflectionProperty $reflectionProperty
31
    ) {
32 2
        $propertyName = $reflectionProperty->getName();
33
        // Resolve annotations
34 2
        $annotations = $this->reader->getPropertyAnnotations($reflectionProperty);
35 2
        if (count($annotations)) {
36
            // Define property if not exists
37 2
            if (!$classDefinition->hasProperty($propertyName)) {
38 2
                $classDefinition->defineProperty($propertyName);
39
            }
40
            // Exec annotations
41 2
            foreach ($annotations as $annotation) {
42 2
                if ($annotation instanceof ResolvePropertyInterface) {
43 2
                    $annotation->resolveProperty($analyzer, $classDefinition, $reflectionProperty);
44
                }
45
            }
46
        }
47 2
    }
48
}
49