Completed
Push — feature/EVO-7278-security-and-... ( ae4d63...67cd5b )
by
unknown
26:50 queued 21:17
created

EmptyExtRefListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 19
rs 10
c 0
b 0
f 0
ccs 0
cts 7
cp 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A onPreSerialize() 0 7 3
1
<?php
2
/**
3
 * see that empty extrefs get rendered as type Empty, ie as null
4
 */
5
6
namespace Graviton\DocumentBundle\Serializer\Listener;
7
8
use Graviton\DocumentBundle\Document\ExtRefHoldingDocumentInterface;
9
use JMS\Serializer\EventDispatcher\PreSerializeEvent;
10
11
/**
12
 *
13
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
14
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
15
 * @link     http://swisscom.ch
16
 */
17
class EmptyExtRefListener
18
{
19
20
    /**
21
     * if is empty extref object, divert serializing to type Empty, which creates a null instead of empty object
22
     *
23
     * @param PreSerializeEvent $event event
24
     *
25
     * @return void
26
     * @throws \Exception
27
     */
28
    public function onPreSerialize(PreSerializeEvent $event)
29
    {
30
        $object = $event->getObject();
31
        if ($object instanceof ExtRefHoldingDocumentInterface && $object->isEmptyExtRefObject() === true) {
32
            $event->setType('Empty', [$object]);
33
        }
34
    }
35
}
36