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

AggregateHydrator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 88.24%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A canHydrate() 0 4 1
A extract() 0 8 3
A hydrate() 0 8 3
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