SerializingDecoder::decode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\yaysondb\Engine;
6
7
/**
8
 * Decoder using serialize() as backend
9
 */
10
class SerializingDecoder implements DecoderInterface
11
{
12
    /**
13
     * Serialize content
14
     */
15
    public function encode(array $content): string
16
    {
17
        return serialize($content);
18
    }
19
20
    /**
21
     * Unserialize content
22
     */
23
    public function decode(string $source): array
24
    {
25
        if ('' == $source) {
26
            return [];
27
        }
28
29
        return (array)unserialize($source);
30
    }
31
}
32