JsonSerializer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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 5
    public function __construct($decodeAssoc = true)
17
    {
18 5
        $this->decodeAssoc = $decodeAssoc;
19 5
    }
20
21
    /**
22
     * @param $item
23
     * @return mixed
24
     */
25 5
    public function serialize($item)
26
    {
27 5
        return json_encode($item);
28
    }
29
30
    /**
31
     * @param $item
32
     * @return mixed
33
     */
34 5
    public function deserialize($item)
35
    {
36 5
        return json_decode($item, $this->decodeAssoc);
37
    }
38
}