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.
Completed
Push — master ( 1978d2...e2f699 )
by William
03:55
created

Serializer/EventSubscriber/JsonEventSubscriber.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
        $embeddeds = $this->embeddedsFactory->create($object, $context);
0 ignored issues
show
$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...
84
        $links     = $this->linksFactory->create($object, $context);
0 ignored issues
show
$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...
85
86
        $embeddeds = $this->embeddedsInlineDeferrer->handleItems($object, $embeddeds, $context);
0 ignored issues
show
$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
        $links  = $this->linksInlineDeferrer->handleItems($object, $links, $context);
0 ignored issues
show
$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...
88
89
        if (count($links) > 0) {
90
            $this->jsonSerializer->serializeLinks($links, $event->getVisitor(), $context);
0 ignored issues
show
$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...
$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...
91
        }
92
93
        if (count($embeddeds) > 0) {
94
            $this->jsonSerializer->serializeEmbeddeds($embeddeds, $event->getVisitor(), $context);
0 ignored issues
show
$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...
$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...
95
        }
96
    }
97
}
98