Completed
Push — master ( c4d148...c0e5c2 )
by Frederik
02:33
created

JsonSerializer::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
namespace Genkgo\Cache\Serializer;
3
4
use Genkgo\Cache\SerializerInterface;
5
6
final class JsonSerializer implements SerializerInterface {
7
8
    /**
9
     * @var bool
10
     */
11
    private $decodeAssoc;
12
13
    /**
14
     * @param bool $decodeAssoc
15
     */
16
    public function __construct($decodeAssoc = true)
17
    {
18
        $this->decodeAssoc = $decodeAssoc;
19
    }
20
21
    /**
22
     * @param $item
23
     * @return mixed
24
     */
25
    public function serialize($item)
26
    {
27
        return json_encode($item);
28
    }
29
30
    /**
31
     * @param $item
32
     * @return mixed
33
     */
34
    public function deserialize($item)
35
    {
36
        return json_decode($item, $this->decodeAssoc);
37
    }
38
}