Completed
Push — master ( 036719...7e3b96 )
by Vitaly
03:14
created

CollectionPropertyResolver::resolve()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.7972
c 0
b 0
f 0
cc 4
eloc 10
nc 2
nop 2
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\containercollection;
9
10
use samsonframework\container\configurator\PropertyConfiguratorInterface;
11
use samsonframework\container\metadata\ClassMetadata;
12
use samsonframework\container\resolver\PropertyResolverTrait;
13
14
/**
15
 * Collection property resolver class.
16
 *
17
 * @author Vitaly Iegorov <[email protected]>
18
 */
19
class CollectionPropertyResolver extends AbstractCollectionResolver implements CollectionResolverInterface
20
{
21
    use PropertyResolverTrait;
22
23
    /** Collection property key */
24
    const KEY = 'properties';
25
26
    /**
27
     * {@inheritDoc}
28
     */
29
    public function resolve(array $configurationArray, ClassMetadata $classMetadata)
30
    {
31
        // Iterate collection
32
        if (array_key_exists(self::KEY, $configurationArray)) {
33
            $reflectionClass = new \ReflectionClass($classMetadata->className);
34
35
            // Iterate configured properties
36
            foreach ($configurationArray[self::KEY] as $propertyName => $propertyDataArray) {
37
                $propertyMetadata = $this->resolvePropertyMetadata(
38
                    $reflectionClass->getProperty($propertyName),
39
                    $classMetadata
40
                );
41
42
                // Process attributes
43
                foreach ($this->getAttributeConfigurator($propertyDataArray) as $configurator) {
44
                    /** @var PropertyConfiguratorInterface $configurator Parse property metadata */
45
                    $configurator->toPropertyMetadata($propertyMetadata);
46
                }
47
            }
48
        }
49
50
        return $classMetadata;
51
    }
52
}
53