Test Failed
Push — master ( 3eb0e4...9196b6 )
by Ivan
02:13
created

MatchFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addHydrator() 0 4 1
A createProperty() 0 14 3
A flattenProperty() 0 14 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Everlution\Navigation\Factory;
6
7
use Everlution\Navigation\Factory\Build\PropertyConfig;
8
use Everlution\Navigation\Factory\Build\UnsupportedItemClassException;
9
use Everlution\Navigation\Property\Property;
10
11
/**
12
 * Class MatchFactory.
13
 * @author Ivan Barlog <[email protected]>
14
 */
15
class MatchFactory extends HydratorContainer implements PropertyFactory
16
{
17
    public function addHydrator(PropertyConfig $config)
18
    {
19
        return $this->add($config);
20
    }
21
22
    /**
23
     * @param array $config
24
     * @return Property
25
     */
26
    public function createProperty(array $config): Property
27
    {
28
        $instance = null;
29
        /** @var PropertyConfig $hydrator */
30
        foreach ($this->getHydrators() as $hydrator) {
31
            try {
32
                $instance = $hydrator->toObject($config);
33
            } catch (UnsupportedItemClassException $exception) {
34
                continue;
35
            }
36
        }
37
38
        return $instance;
39
    }
40
41
    /**
42
     * @param Property $property
43
     * @return array
44
     */
45
    public function flattenProperty(Property $property): array
46
    {
47
        $items = [];
48
        /** @var PropertyConfig $hydrator */
49
        foreach ($this->getHydrators() as $hydrator) {
50
            try {
51
                $items[] = $hydrator->toArray($property);
52
            } catch (UnsupportedItemClassException $exception) {
53
                continue;
54
            }
55
        }
56
57
        return $items;
58
    }
59
}
60