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

AnnotationPropertyAnalyzer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 29
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B analyze() 0 21 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