Completed
Push — master ( 8f61de...6beb52 )
by Vitaly
02:52
created

resolveClassPropertyAnnotations()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 3
eloc 4
nc 3
nop 2
crap 3
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 07.08.16 at 13:04
5
 */
6
namespace samsonframework\container\annotation;
7
8
use samsonframework\container\configurator\PropertyConfiguratorInterface;
9
use samsonframework\container\metadata\ClassMetadata;
10
use samsonframework\container\metadata\PropertyMetadata;
11
use samsonframework\container\resolver\PropertyResolverTrait;
12
13
/**
14
 * Class properties annotation resolver.
15
 */
16
class AnnotationPropertyResolver extends AbstractAnnotationResolver implements AnnotationResolverInterface
17
{
18
    use PropertyResolverTrait;
19
20
    /**
21
     * {@inheritDoc}
22
     */
23 11
    public function resolve(\ReflectionClass $classReflection, ClassMetadata $classMetadata)
24
    {
25
        /** @var \ReflectionProperty $property */
26 11
        foreach ($classReflection->getProperties() as $property) {
27 10
            $this->resolveClassPropertyAnnotations(
28
                $property,
29 10
                $this->resolvePropertyMetadata($property, $classMetadata)
30
            );
31
        }
32
33 11
        return $classMetadata;
34
    }
35
36
    /**
37
     * Resolve class property annotations.
38
     *
39
     * @param \ReflectionProperty $property
40
     * @param PropertyMetadata    $propertyMetadata
41
     */
42 10
    protected function resolveClassPropertyAnnotations(\ReflectionProperty $property, PropertyMetadata $propertyMetadata)
43
    {
44
        /** @var PropertyConfiguratorInterface $annotation Read class annotations */
45 10
        foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
46 10
            if ($annotation instanceof PropertyConfiguratorInterface) {
47 10
                $annotation->toPropertyMetadata($propertyMetadata);
48
            }
49
        }
50 10
    }
51
}
52