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.

JsonEventSubscriber   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 10 1
A __construct() 0 13 1
A onPostSerialize() 0 23 3
1
<?php
2
3
namespace Hateoas\Serializer\EventSubscriber;
4
5
use Hateoas\Factory\EmbeddedsFactory;
6
use Hateoas\Factory\LinksFactory;
7
use Hateoas\Serializer\JsonSerializerInterface;
8
use Hateoas\Serializer\Metadata\InlineDeferrer;
9
use JMS\Serializer\EventDispatcher\Events;
10
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
11
use JMS\Serializer\EventDispatcher\ObjectEvent;
12
13
/**
14
 * @author Adrien Brault <[email protected]>
15
 */
16
class JsonEventSubscriber implements EventSubscriberInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public static function getSubscribedEvents()
22
    {
23
        return array(
24
            array(
25
                'event'  => Events::POST_SERIALIZE,
26
                'format' => 'json',
27
                'method' => 'onPostSerialize',
28
            ),
29
        );
30
    }
31
32
    /**
33
     * @var JsonSerializerInterface
34
     */
35
    private $jsonSerializer;
36
37
    /**
38
     * @var LinksFactory
39
     */
40
    private $linksFactory;
41
42
    /**
43
     * @var EmbeddedsFactory
44
     */
45
    private $embeddedsFactory;
46
47
    /**
48
     * @var InlineDeferrer
49
     */
50
    private $embeddedsInlineDeferrer;
51
52
    /**
53
     * @var InlineDeferrer
54
     */
55
    private $linksInlineDeferrer;
56
57
    /**
58
     * @param JsonSerializerInterface $jsonSerializer
59
     * @param LinksFactory            $linksFactory
60
     * @param EmbeddedsFactory        $embeddedsFactory
61
     * @param InlineDeferrer          $embeddedsInlineDeferrer
62
     * @param InlineDeferrer          $linksInleDeferrer
63
     */
64
    public function __construct(
65
        JsonSerializerInterface $jsonSerializer,
66
        LinksFactory $linksFactory,
67
        EmbeddedsFactory $embeddedsFactory,
68
        InlineDeferrer $embeddedsInlineDeferrer,
69
        InlineDeferrer $linksInleDeferrer
70
    ) {
71
        $this->jsonSerializer          = $jsonSerializer;
72
        $this->linksFactory            = $linksFactory;
73
        $this->embeddedsFactory        = $embeddedsFactory;
74
        $this->embeddedsInlineDeferrer = $embeddedsInlineDeferrer;
75
        $this->linksInlineDeferrer     = $linksInleDeferrer;
76
    }
77
78
    public function onPostSerialize(ObjectEvent $event)
79
    {
80
        $object  = $event->getObject();
81
        $context = $event->getContext();
82
83
        $context->startVisiting($object);
84
85
        $embeddeds = $this->embeddedsFactory->create($object, $context);
0 ignored issues
show
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...
86
        $links     = $this->linksFactory->create($object, $context);
0 ignored issues
show
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...
87
88
        $embeddeds = $this->embeddedsInlineDeferrer->handleItems($object, $embeddeds, $context);
0 ignored issues
show
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...
89
        $links  = $this->linksInlineDeferrer->handleItems($object, $links, $context);
0 ignored issues
show
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...
90
91
        if (count($links) > 0) {
92
            $this->jsonSerializer->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\JsonSerializationVisitor>. 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...
93
        }
94
95
        if (count($embeddeds) > 0) {
96
            $this->jsonSerializer->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\JsonSerializationVisitor>. 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...
97
        }
98
99
        $context->stopVisiting($object);
100
    }
101
}
102