Completed
Push — master ( 0d7c83...11b403 )
by Vitaly
02:57
created

CollectionKeyResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 48
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
B resolveKey() 0 21 5
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 17.08.16 at 10:14
5
 */
6
namespace samsonframework\container\collection;
7
8
use samsonframework\container\metadata\ClassMetadata;
9
10
/**
11
 * Collection key resolver.
12
 *
13
 * @author Vitaly Egorov <[email protected]>
14
 */
15
class CollectionKeyResolver extends AbstractCollectionResolver
16
{
17
    /** @var  CollectionAttributeResolver */
18
    protected $attributeResolver;
19
20
    /**
21
     * CollectionKeyResolver constructor.
22
     *
23
     * @param array                       $configurators
24
     *
25
     * @param CollectionAttributeResolver $attributeResolver
26
     */
27
    public function __construct(array $configurators, CollectionAttributeResolver $attributeResolver)
28
    {
29
        $this->attributeResolver = $attributeResolver;
30
31
        // Fill with key nested interface
32
        $this->configurators = $this->getConfiguratorsByInterface(
0 ignored issues
show
Bug introduced by
The property configurators does not seem to exist. Did you mean collectionConfigurators?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The method getConfiguratorsByInterface() does not seem to exist on object<samsonframework\c...\CollectionKeyResolver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
            $configurators,
34
            CollectionKeyConfiguratorInterface::class
35
        );
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public function resolveKey(string $key, array $data, ClassMetadata $classMetadata = null)
42
    {
43
        // If this is supported collection key configurator
44
        if (array_key_exists($key, $this->configurators)) {
0 ignored issues
show
Bug introduced by
The property configurators does not seem to exist. Did you mean collectionConfigurators?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
45
            // Create configurator and retrieve metadata
46
            $metadata = (new $this->configurators[$key]($data))->resolve($data, $classMetadata);
0 ignored issues
show
Bug introduced by
The property configurators does not seem to exist. Did you mean collectionConfigurators?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
47
48
            // If we have parsed metadata
49
            if ($metadata !== null) {
50
                // And we have attributes for this key
51
                if (array_key_exists('@attributes', $data)) {
52
                    // Resolve attributes
53
                    foreach ($data['@attributes'] as $attributeKey => $attributeValue) {
54
                        $this->attributeResolver->resolveAttribute($attributeKey, $attributeValue, $metadata);
55
                    }
56
                }
57
            }
58
        }
59
60
        return $classMetadata;
61
    }
62
}
63