JsonSerializer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 33
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

3 Methods

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