GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

XmlEventSubscriber   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 64
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 10 1
A __construct() 0 6 1
A onPostSerialize() 0 20 3
1
<?php
2
3
namespace Hateoas\Serializer\EventSubscriber;
4
5
use Hateoas\Factory\EmbeddedsFactory;
6
use Hateoas\Factory\LinksFactory;
7
use Hateoas\Serializer\XmlSerializerInterface;
8
use JMS\Serializer\EventDispatcher\Events;
9
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
10
use JMS\Serializer\EventDispatcher\ObjectEvent;
11
12
/**
13
 * @author Adrien Brault <[email protected]>
14
 */
15
class XmlEventSubscriber implements EventSubscriberInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public static function getSubscribedEvents()
21
    {
22
        return array(
23
            array(
24
                'event'  => Events::POST_SERIALIZE,
25
                'format' => 'xml',
26
                'method' => 'onPostSerialize',
27
            ),
28
        );
29
    }
30
31
    /**
32
     * @var XmlSerializerInterface
33
     */
34
    private $xmlSerializer;
35
36
    /**
37
     * @var LinksFactory
38
     */
39
    private $linksFactory;
40
41
    /**
42
     * @var EmbeddedsFactory
43
     */
44
    private $embeddedsFactory;
45
46
    /**
47
     * @param XmlSerializerInterface $xmlSerializer
48
     * @param LinksFactory           $linksFactory
49
     * @param EmbeddedsFactory       $embeddedsFactory
50
     */
51
    public function __construct(XmlSerializerInterface $xmlSerializer, LinksFactory $linksFactory, EmbeddedsFactory $embeddedsFactory)
52
    {
53
        $this->xmlSerializer    = $xmlSerializer;
54
        $this->linksFactory     = $linksFactory;
55
        $this->embeddedsFactory = $embeddedsFactory;
56
    }
57
58
    public function onPostSerialize(ObjectEvent $event)
59
    {
60
        $object  = $event->getObject();
61
        $context = $event->getContext();
62
63
        $context->startVisiting($object);
64
        
65
        $embeddeds = $this->embeddedsFactory->create($object, $context);
0 ignored issues
show
Compatibility introduced by Adrien Brault
$context of type object<JMS\Serializer\Context> is not a sub-type of object<JMS\Serializer\SerializationContext>. It seems like you assume a child class of the class JMS\Serializer\Context to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
66
        $links     = $this->linksFactory->create($object, $context);
0 ignored issues
show
Compatibility introduced by Adrien Brault
$context of type object<JMS\Serializer\Context> is not a sub-type of object<JMS\Serializer\SerializationContext>. It seems like you assume a child class of the class JMS\Serializer\Context to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
67
68
        if (count($links) > 0) {
69
            $this->xmlSerializer->serializeLinks($links, $event->getVisitor(), $context);
0 ignored issues
show
Compatibility introduced by William DURAND
$event->getVisitor() of type object<JMS\Serializer\VisitorInterface> is not a sub-type of object<JMS\Serializer\XmlSerializationVisitor>. It seems like you assume a concrete implementation of the interface JMS\Serializer\VisitorInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Compatibility introduced by William DURAND
$context of type object<JMS\Serializer\Context> is not a sub-type of object<JMS\Serializer\SerializationContext>. It seems like you assume a child class of the class JMS\Serializer\Context to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
70
        }
71
72
        if (count($embeddeds) > 0) {
73
            $this->xmlSerializer->serializeEmbeddeds($embeddeds, $event->getVisitor(), $context);
0 ignored issues
show
Compatibility introduced by William DURAND
$event->getVisitor() of type object<JMS\Serializer\VisitorInterface> is not a sub-type of object<JMS\Serializer\XmlSerializationVisitor>. It seems like you assume a concrete implementation of the interface JMS\Serializer\VisitorInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Compatibility introduced by William DURAND
$context of type object<JMS\Serializer\Context> is not a sub-type of object<JMS\Serializer\SerializationContext>. It seems like you assume a child class of the class JMS\Serializer\Context to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
74
        }
75
76
        $context->stopVisiting($object);
77
    }
78
}
79