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

AnnotationPropertyResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 12 2
A resolveClassPropertyAnnotations() 0 9 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