Completed
Push — master ( 831cd8...4849d0 )
by
unknown
45:37 queued 20:41
created

getSubscribingMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MovingImage\Client\VMPro\Subscriber;
6
7
use JMS\Serializer\DeserializationContext;
8
use JMS\Serializer\GraphNavigatorInterface;
9
use JMS\Serializer\Handler\SubscribingHandlerInterface;
10
use JMS\Serializer\JsonDeserializationVisitor;
11
use MovingImage\Client\VMPro\Entity\Attachment;
12
13
class DeserializeAttachmentSubscriber implements SubscribingHandlerInterface
14
{
15
16
    /**
17
     * Return format:
18
     *
19
     *      array(
20
     *          array(
21
     *              'direction' => GraphNavigatorInterface::DIRECTION_SERIALIZATION,
22
     *              'format' => 'json',
23
     *              'type' => 'DateTime',
24
     *              'method' => 'serializeDateTimeToJson',
25
     *          ),
26
     *      )
27
     *
28
     * The direction and method keys can be omitted.
29
     *
30
     * @return array
31
     *
32
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint
33
     */
34
    public static function getSubscribingMethods()
35
    {
36
        return [
37
            [
38
                'direction' => GraphNavigatorInterface::DIRECTION_DESERIALIZATION,
39
                'format' => 'json',
40
                'type' => Attachment::class,
41
                'method' => 'deserialize',
42
            ]
43
        ];
44
    }
45
    public function deserialize(JsonDeserializationVisitor $visitor, array $data, array $type, DeserializationContext $context)
0 ignored issues
show
Unused Code introduced by
The parameter $visitor is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    {
47
        $attachment = new Attachment();
48
        if (isset($data['data']['id'])) {
49
            $attachment->setId($data['data']['id']);
50
        }
51
52
        if (isset($data['data']['fileName'])) {
53
            $attachment->setFileName($data['data']['fileName']);
54
        }
55
56
        if (isset($data['data']['downloadUrl'])) {
57
            $attachment->setDownloadUrl($data['data']['downloadUrl']);
58
        }
59
60
        if (isset($data['data']['fileSize'])) {
61
            $attachment->setFileSize($data['data']['fileSize']);
62
        }
63
64
        if (isset($data['type']['name'])) {
65
            $attachment->setType($data['type']['name']);
66
        }
67
68
        return $attachment;
69
    }
70
71
}