DateTimeHandler::getSubscribingMethods()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace CultureKings\Afterpay\Handler;
4
5
use Carbon\Carbon;
6
use JMS\Serializer\GraphNavigator;
7
use JMS\Serializer\Handler\SubscribingHandlerInterface;
8
use JMS\Serializer\JsonDeserializationVisitor;
9
use JMS\Serializer\JsonSerializationVisitor;
10
11
/**
12
 * Class DateTimeHandler
13
 * @package CultureKings\Afterpay\Handler
14
 */
15
class DateTimeHandler implements SubscribingHandlerInterface
16
{
17
    /**
18
     * @return array
19
     */
20
    public static function getSubscribingMethods()
21
    {
22
        return [
23
            [
24
                'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
25
                'format' => 'json',
26
                'type' => 'DateTime',
27
                'method' => 'deserializeDateTimeFromJson',
28
            ],
29
            [
30
                'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
31
                'format' => 'json',
32
                'type' => 'DateTime',
33
                'method' => 'serializeDateTimeToJson',
34
            ],
35
        ];
36
    }
37
38
    /**
39
     * @param JsonDeserializationVisitor $visitor
40
     * @param string                     $data
41
     * @param array                      $type
42
     * @return null|Carbon
43
     */
44
    public function deserializeDateTimeFromJson(JsonDeserializationVisitor $visitor, $data, array $type)
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...
45
    {
46
        if (null === $data) {
47
            return null;
48
        }
49
50
        return Carbon::parse($data);
51
    }
52
53
    /**
54
     * @param JsonSerializationVisitor $visitor
55
     * @param \DateTimeInterface       $data
56
     * @param array                    $type
57
     *
58
     * @return string
59
     */
60
    public function serializeDateTimeToJson(JsonSerializationVisitor $visitor, $data, array $type)
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...
61
    {
62
        return $data->format($type['params'][0]);
63
    }
64
}
65