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

ThemeHydrator::extract()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 2
nop 1
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