Completed
Push — master ( c93e0a...f87b82 )
by Mario
09:30 queued 03:59
created

AggregateHydrator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 51
ccs 15
cts 15
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A extract() 0 10 3
A hydrate() 0 10 3
A canHydrate() 0 4 1
1
<?php
2
3
namespace Marek\Toggable\Hydrator;
4
5
/**
6
 * Class AggregateHydrator
7
 * @package Marek\Toggable\Hydrator
8
 */
9
class AggregateHydrator implements HydratorInterface
10
{
11
    /**
12
     * @var HydratorInterface[]
13
     */
14
    private $hydrators;
15
16
    /**
17
     * @param \Marek\Toggable\Hydrator\HydratorInterface $hydrator
18
     */
19 19
    public function add(HydratorInterface $hydrator)
20
    {
21 19
        $this->hydrators[] = $hydrator;
22 19
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 2
    public function extract($object)
28
    {
29 2
        foreach($this->hydrators as $hydrator) {
30 2
            if ($hydrator->canHydrate($object)) {
31 2
                return $hydrator->extract($object);
32
            }
33
        }
34
35 1
        return $object;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 2
    public function hydrate(array $data, $object)
42
    {
43 2
        foreach($this->hydrators as $hydrator) {
44 2
            if ($hydrator->canHydrate($object)) {
45 2
                return $hydrator->hydrate($data, $object);
46
            }
47
        }
48
49 1
        return $data;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 1
    public function canHydrate($object)
56
    {
57 1
        return true;
58
    }
59
}
60