Completed
Push — master ( fecb59...e32f72 )
by Paweł
29:36
created

PackageSubscriber::onPostDeserialize()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 3
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Bridge Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\BridgeBundle\Serializer;
16
17
use Doctrine\Common\Collections\ArrayCollection;
18
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
19
use JMS\Serializer\EventDispatcher\ObjectEvent;
20
use SWP\Component\Bridge\Model\PackageInterface;
21
22
class PackageSubscriber implements EventSubscriberInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 2
    public static function getSubscribedEvents()
28
    {
29
        return [
30
            [
31
                'event' => 'serializer.post_deserialize',
32
                'method' => 'onPostDeserialize',
33 2
            ],
34
        ];
35
    }
36
37
    /**
38
     * @param ObjectEvent $event
39
     */
40 13
    public function onPostDeserialize(ObjectEvent $event)
41
    {
42 13
        if ($event->getObject() instanceof PackageInterface) {
43
            /** @var PackageInterface $package */
44 13
            $package = $event->getObject();
45
46 13
            if (null === $package->getItems()) {
47 3
                $package->setItems(new ArrayCollection());
48
            }
49
        }
50 13
    }
51
}
52