JsonObjectSerializer::unserialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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