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

CollectionAttributeResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
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\configurator\ClassConfiguratorInterface;
9
use samsonframework\container\configurator\MethodConfiguratorInterface;
10
use samsonframework\container\configurator\PropertyConfiguratorInterface;
11
use samsonframework\container\metadata\AbstractMetadata;
12
use samsonframework\container\metadata\ClassMetadata;
13
use samsonframework\container\metadata\MethodMetadata;
14
use samsonframework\container\metadata\PropertyMetadata;
15
16
/**
17
 * Collection attribute resolver.
18
 *
19
 * @author Vitaly Egorov <[email protected]>
20
 */
21
class CollectionAttributeResolver extends AbstractCollectionResolver
22
{
23
    /**
24
     * CollectionAttributeResolver constructor.
25
     *
26
     * @param array $configurators
27
     *
28
     * @throws \InvalidArgumentException
29
     */
30
    public function __construct(array $configurators)
31
    {
32
        // Fill with key nested interface
33
        $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...ctionAttributeResolver>.

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...
34
            $configurators,
35
            CollectionAttributeConfiguratorInterface::class
36
        );
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function resolveAttribute(string $key, string $value, AbstractMetadata $metadata)
43
    {
44
        // If this is supported collection configurator
45
        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...
46
            /** @var CollectionAttributeConfiguratorInterface $configurator Create configurator */
47
            $configurator = new $this->configurators[$key]($value);
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...
48
            if ($configurator instanceof ClassConfiguratorInterface && $metadata instanceof ClassMetadata) {
49
                $configurator->toClassMetadata($metadata);
50
            }
51
            if ($configurator instanceof PropertyConfiguratorInterface && $metadata instanceof PropertyMetadata) {
52
                $configurator->toPropertyMetadata($metadata);
53
            }
54
            if ($configurator instanceof MethodConfiguratorInterface && $metadata instanceof MethodMetadata) {
55
                $configurator->toMethodMetadata($metadata);
56
            }
57
        }
58
59
        return $metadata;
60
    }
61
}
62