Completed
Push — master ( 3cb594...17b364 )
by Peter
04:28
created

SymfonySerializer::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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\Component\Command\Queue\Serializer;
12
13
use GpsLab\Component\Command\Command;
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, Command::class, $this->format);
58
    }
59
}
60