SymfonySerializer::serialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Domain\Event\Queue\Serializer;
12
13
use GpsLab\Domain\Event\Event;
14
use Symfony\Component\Serializer\SerializerInterface;
15
16
class SymfonySerializer implements Serializer
17
{
18
    const DEFAULT_FORMAT = 'predis';
19
20
    /**
21
     * @var SerializerInterface
22
     */
23
    private $serializer;
24
25
    /**
26
     * @var string
27
     */
28
    private $format = self::DEFAULT_FORMAT;
29
30
    /**
31
     * @param SerializerInterface $serializer
32
     * @param string|null         $format
33
     */
34 4
    public function __construct(SerializerInterface $serializer, $format = null)
35
    {
36 4
        $this->serializer = $serializer;
37 4
        $this->format = $format ?: self::DEFAULT_FORMAT;
38 4
    }
39
40
    /**
41
     * @param object $data
42
     *
43
     * @return string
44
     */
45 2
    public function serialize($data)
46
    {
47 2
        return $this->serializer->serialize($data, $this->format);
48
    }
49
50
    /**
51
     * @param string $data
52
     *
53
     * @return object
54
     */
55 2
    public function deserialize($data)
56
    {
57 2
        return $this->serializer->deserialize($data, Event::class, $this->format);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->serializer->deser...:class, $this->format); of type object|array adds the type array to the return on line 57 which is incompatible with the return type declared by the interface GpsLab\Domain\Event\Queu...Serializer::deserialize of type object.
Loading history...
58
    }
59
}
60