Completed
Push — master ( 79d213...eeff33 )
by Kamil
23:15
created

ThemeHydrator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A extract() 0 10 3
A hydrate() 0 8 3
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ThemeBundle\Hydrator;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Zend\Hydrator\HydratorInterface;
17
18
/**
19
 * @author Kamil Kokot <[email protected]>
20
 */
21
final class ThemeHydrator implements HydratorInterface
22
{
23
    /**
24
     * @var HydratorInterface
25
     */
26
    private $decoratedHydrator;
27
28
    /**
29
     * @param HydratorInterface $decoratedHydrator
30
     */
31
    public function __construct(HydratorInterface $decoratedHydrator)
32
    {
33
        $this->decoratedHydrator = $decoratedHydrator;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function extract($object)
40
    {
41
        $data = $this->decoratedHydrator->extract($object);
42
43
        if (isset($data['parents']) && $data['parents'] instanceof Collection) {
44
            $data['parents'] = $data['parents']->toArray();
45
        }
46
47
        return $data;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function hydrate(array $data, $object)
54
    {
55
        if (isset($data['parents']) && is_array($data['parents'])) {
56
            $data['parents'] = new ArrayCollection($data['parents']);
57
        }
58
59
        return $this->decoratedHydrator->hydrate($data, $object);
60
    }
61
}
62