Passed
Branch master (0b4094)
by Alexander
01:32
created

JsonSerializer::unserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
namespace Yiisoft\Cache\Serializer;
3
4
/**
5
 * JsonSerializer serializes data in JSON format.
6
 */
7
final class JsonSerializer implements SerializerInterface
8
{
9
    private $options;
10
11
    /**
12
     * JsonSerializer constructor.
13
     *
14
     * @param int $options integer the encoding options. For more details please refer to
15
     * <http://www.php.net/manual/en/function.json-encode.php>.
16
     * Default is `JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE`.
17
     */
18
    public function __construct(int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
19
    {
20
        $this->options = $options;
21
    }
22
23
    public function serialize($value): string
24
    {
25
        return json_encode($value, $this->options);
26
    }
27
28
    public function unserialize(string $value)
29
    {
30
        return json_decode($value, true);
31
    }
32
}
33