Completed
Push — master ( 7a9694...a77116 )
by Rafał
03:05
created

PackageSubscriber::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 4
nc 1
nop 0
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
    public static function getSubscribedEvents()
28
    {
29
        return [
30
            [
31
                'event' => 'serializer.post_deserialize',
32
                'method' => 'onPostDeserialize',
33
            ],
34
        ];
35
    }
36
37
    /**
38
     * @param ObjectEvent $event
39
     */
40
    public function onPostDeserialize(ObjectEvent $event)
41
    {
42
        if ($event->getObject() instanceof PackageInterface) {
43
            /** @var PackageInterface $package */
44
            $package = $event->getObject();
45
46
            if (null === $package->getItems()) {
47
                $package->setItems(new ArrayCollection());
0 ignored issues
show
Bug introduced by
The method setItems() does not seem to exist on object<SWP\Component\Bri...Model\PackageInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
            }
49
        }
50
    }
51
}
52