Completed
Push — master ( 17312a...d17d72 )
by Mario
03:12
created

AggregateHydrator::hydrate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 6
cp 0.8333
rs 9.4285
cc 3
eloc 4
nc 3
nop 2
crap 3.0416
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 16
    public function add(HydratorInterface $hydrator)
20
    {
21 16
        $this->hydrators[] = $hydrator;
22 16
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 1
    public function extract($object)
28
    {
29 1
        foreach($this->hydrators as $hydrator) {
30 1
            if ($hydrator->canHydrate($object)) {
31 1
                return $hydrator->extract($object);
32
            }
33 1
        }
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 1
    public function hydrate(array $data, $object)
40
    {
41 1
        foreach($this->hydrators as $hydrator) {
42 1
            if ($hydrator->canHydrate($object)) {
43 1
                return $hydrator->hydrate($data, $object);
44
            }
45 1
        }
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 1
    public function canHydrate($object)
52
    {
53 1
        return true;
54
    }
55
}
56