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

CollectionPropertyResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 34
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B resolve() 0 23 4
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