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.

TimeZoneCustomSerializer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 47
rs 10
c 0
b 0
f 0
ccs 10
cts 10
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 8 2
A deserialize() 0 8 2
A canHandle() 0 4 1
1
<?php
2
3
namespace RemiSan\Serializer\CustomSerializer;
4
5
class TimeZoneCustomSerializer implements CustomSerializer
6
{
7
    /**
8
     * Serialize the object
9
     *
10
     * @param object $object
11
     *
12
     * @return array|void
13
     */
14 12
    public function serialize($object)
15
    {
16 12
        if (!$this->canHandle(get_class($object))) {
17 3
            throw new \InvalidArgumentException();
18
        }
19
20 9
        return [ $object->getName() ];
21
    }
22
23
    /**
24
     * Deserialize the object
25
     *
26
     * @param array  $serialized
27
     * @param string $fqcn the fully qualified class name
28
     *
29
     * @return object
30
     */
31 12
    public function deserialize(array $serialized, $fqcn)
32
    {
33 12
        if (!$this->canHandle($fqcn)) {
34 3
            throw new \InvalidArgumentException();
35
        }
36
37 9
        return new \DateTimeZone($serialized[0]);
38
    }
39
40
    /**
41
     * Can the custom serializer (de)serialize the objects of this class
42
     *
43
     * @param string $className
44
     *
45
     * @return boolean
46
     */
47 30
    public function canHandle($className)
48
    {
49 30
        return $className === \DateTimeZone::class;
50
    }
51
}
52