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

SymfonySerializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 44
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A serialize() 0 4 1
A deserialize() 0 4 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