DocumentDataWrapper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 9 1
A wrapData() 0 10 3
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
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 Xabbuh\XApi\Serializer\Event;
13
14
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
15
use JMS\Serializer\EventDispatcher\PreDeserializeEvent;
16
17
/**
18
 * Wraps a JSON encoded xAPI document into a Document instance.
19
 *
20
 * @author Christian Flothmann <[email protected]>
21
 */
22
class DocumentDataWrapper implements EventSubscriberInterface
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public static function getSubscribedEvents()
28
    {
29
        return array(
30
            array(
31
                'event' => 'serializer.pre_deserialize',
32
                'method' => 'wrapData',
33
            ),
34
        );
35
    }
36
37
    public function wrapData(PreDeserializeEvent $event)
38
    {
39
        $type = $event->getType();
40
        $handledClass = 'Xabbuh\XApi\Model\DocumentData';
41
42
        if ($handledClass == $type['name'] || is_subclass_of($type['name'], $handledClass)) {
43
            $data = $event->getData();
44
            $event->setData(array('data' => $data));
45
        }
46
    }
47
}
48