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   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 34
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 13 2
A deserialize() 0 12 2
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
}