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\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 | $context = $event->getContext(); |
||
61 | $embeddeds = $this->embeddedsFactory->create($event->getObject(), $event->getContext()); |
||
0 ignored issues
–
show
|
|||
62 | $links = $this->linksFactory->create($event->getObject(), $event->getContext()); |
||
0 ignored issues
–
show
$event->getContext() 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...
|
|||
63 | |||
64 | if (count($links) > 0) { |
||
65 | $this->xmlSerializer->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\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...
$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 | } |
||
67 | |||
68 | if (count($embeddeds) > 0) { |
||
69 | $this->xmlSerializer->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\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...
$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 | } |
||
73 |
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.