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.

ObjectSelfSerializer::serialize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 6
cts 6
cp 1
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
rs 9.8333
1
<?php
2
namespace SmoothPhp\Serialization;
3
4
use SmoothPhp\Contracts\Serialization\Serializer;
5
use SmoothPhp\Contracts\Serialization\Serializable;
6
use SmoothPhp\Serialization\Exception\SerializationException;
7
8
/**
9
 * Class ObjectSelfSerializer
10
 * @package SmoothPhp\Serialization
11
 * @author Simon Bennett <[email protected]>
12
 */
13
final class ObjectSelfSerializer implements Serializer
14
{
15
    /**
16
     * {@inheritDoc}
17
     */
18 6
    public function serialize($object)
19
    {
20 6
        if (! $object instanceof Serializable) {
21 3
            throw new SerializationException(sprintf(
22 3
                                                 'Object \'%s\' does not implement Serializable',
23
                                                 get_class($object)
24
                                             ));
25
        }
26
        return array(
27 3
            'class'   => get_class($object),
28 3
            'payload' => $object->serialize()
29
        );
30
    }
31
    /**
32
     * {@inheritDoc}
33
     */
34 6
    public function deserialize(array $serializedObject)
35
    {
36 6
        if (! in_array(Serializable::class, class_implements($serializedObject['class']))) {
37 3
            throw new SerializationException(
38
                sprintf(
39 3
                    'Class \'%s\' does not implement Serializable',
40 3
                    $serializedObject['class']
41
                )
42
            );
43
        }
44 3
        return $serializedObject['class']::deserialize($serializedObject['payload']);
45
    }
46
}