JsonObjectSerializer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A serialize() 0 4 1
A unserialize() 0 4 1
1
<?php
2
3
namespace NilPortugues\MessageBus\Serializer;
4
5
use NilPortugues\MessageBus\Serializer\Contracts\Serializer;
6
use NilPortugues\Serializer\DeepCopySerializer;
7
use NilPortugues\Serializer\Transformer\JsonTransformer;
8
9
class JsonObjectSerializer implements Serializer
10
{
11
    /** @var JsonTransformer */
12
    protected $transformer;
13
14
    /**
15
     * JsonObjectSerializer constructor.
16
     */
17
    public function __construct()
18
    {
19
        $this->transformer = new DeepCopySerializer(new JsonTransformer());
0 ignored issues
show
Documentation Bug introduced by
It seems like new \NilPortugues\Serial...rmer\JsonTransformer()) of type object<NilPortugues\Seri...zer\DeepCopySerializer> is incompatible with the declared type object<NilPortugues\Seri...former\JsonTransformer> of property $transformer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
20
    }
21
22
    /**
23
     * Turns a data structure into a string that can be recovered.
24
     *
25
     * @param mixed $data
26
     *
27
     * @return string
28
     */
29
    public function serialize($data) : string
30
    {
31
        return $this->transformer->serialize($data);
32
    }
33
34
    /**
35
     * Turns string data structure into an usable $data structure.
36
     *
37
     * @param string $data
38
     *
39
     * @return \stdClass
40
     */
41
    public function unserialize(string $data)
42
    {
43
        return (object) json_decode($data);
44
    }
45
}
46