Completed
Push — master ( ad7f0e...8f61de )
by Vitaly
04:01
created

CollectionPropertyResolver::resolve()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 34
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 34
ccs 15
cts 15
cp 1
rs 8.439
cc 5
eloc 15
nc 2
nop 2
crap 5
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by PhpStorm.
4
 * User: root
5
 * Date: 29.07.2016
6
 * Time: 21:38.
7
 */
8
namespace samsonframework\container\collection;
9
10
use samsonframework\container\annotation\AnnotationPropertyResolver;
11
use samsonframework\container\configurator\PropertyConfiguratorInterface;
12
use samsonframework\container\metadata\ClassMetadata;
13
use samsonframework\container\metadata\PropertyMetadata;
14
15
/**
16
 * Collection property resolver class.
17
 *
18
 * @author Vitaly Iegorov <[email protected]>
19
 */
20
class CollectionPropertyResolver extends AbstractCollectionResolver implements CollectionResolverInterface
21
{
22
    /** Collection property key */
23
    const KEY = 'properties';
24
25
    /**
26
     * {@inheritDoc}
27
     */
28 1
    public function resolve(array $classDataArray, ClassMetadata $classMetadata)
29
    {
30
        // Iterate collection
31 1
        if (array_key_exists(self::KEY, $classDataArray)) {
32 1
            $reflectionClass = new \ReflectionClass($classMetadata->className);
33
            // Iterate configured properties
34 1
            foreach ($classDataArray[self::KEY] as $propertyName => $propertyDataArray) {
35 1
                $propertyReflection = $reflectionClass->getProperty($propertyName);
36
37
                // Create method metadata instance
38
                // TODO This code are identical with AnnotationPropertyResolver
39 1
                $propertyMetadata = new PropertyMetadata($classMetadata);
40 1
                $propertyMetadata->name = $propertyReflection->getName();
41 1
                $propertyMetadata->modifiers = $propertyReflection->getModifiers();
42 1
                $propertyMetadata->isPublic = $propertyReflection->isPublic();
43
44
                // Parse property type hint if present
45 1
                if (preg_match(AnnotationPropertyResolver::P_PROPERTY_TYPE_HINT, $propertyReflection->getDocComment(), $matches)) {
46 1
                    list(, $propertyMetadata->typeHint) = $matches;
47
                }
48
49
                // Process attributes
50 1
                foreach ($this->getAttributeConfigurator($propertyDataArray) as $configurator) {
51
                    /** @var PropertyConfiguratorInterface $configurator Parse property metadata */
52 1
                    $configurator->toPropertyMetadata($propertyMetadata);
53
                }
54
55
                // Save property metadata
56 1
                $classMetadata->propertiesMetadata[$propertyMetadata->name] = $propertyMetadata;
57
            }
58
        }
59
60 1
        return $classMetadata;
61
    }
62
}
63