Completed
Push — master ( 019907...013ee6 )
by Vitaly
03:05
created

CollectionClassResolver   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A resolve() 0 13 4
A resolveArrayKeys() 0 4 1
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\configurator\ConfiguratorInterface;
11
use samsonframework\container\metadata\ClassMetadata;
12
13
/**
14
 * Array class resolver class.
15
 * @author Vitaly Iegorov <[email protected]>
16
 */
17
class CollectionClassResolver implements CollectionResolverInterface
18
{
19
    /** Array key name for searching class cofiguration sections */
20
    const KEY_CLASS = 'dependencies';
21
    /** @var array Collection of supported array keys */
22
    protected $keys = [];
23
24
    /**
25
     * ArrayClassResolver constructor.
26
     */
27
    public function __construct()
28
    {
29
        // Gather all supported configuration keys
30
        $this->keys = [];
31
        foreach (get_declared_classes() as $className) {
32
            if (in_array(ConfiguratorInterface::class, class_implements($className), true)) {
33
                $annotationName = substr($className, strrpos($className, '\\') + 1);
34
                $this->keys[strtolower($annotationName)] = $className;
35
            }
36
        }
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function resolve(array $classDataArray, ClassMetadata $classMetadata)
43
    {
44
        foreach ($classDataArray as $item => $configuration) {
45
            // If we have class resolving key
46
            foreach ($this->keys as $key => $className) {
47
                if (array_key_exists($key, $configuration)) {
48
                    (new $className(['value' => $configuration[$key]]))->toClassMetadata($classMetadata);
49
                }
50
            }
51
        }
52
53
        return $classMetadata;
54
    }
55
56
    public function resolveArrayKeys()
57
    {
58
59
    }
60
}
61