PhpDecoder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 4 1
A decode() 0 10 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\yaysondb\Engine;
6
7
/**
8
 * Decoder using var_export as backend
9
 */
10
class PhpDecoder implements DecoderInterface
11
{
12
    /**
13
     * Encode content into php code
14
     */
15
    public function encode(array $content): string
16
    {
17
        return '<?php return ' . var_export($content, true) . ';';
18
    }
19
20
    /**
21
     * Decode source by calling eval
22
     */
23
    public function decode(string $source): array
24
    {
25
        if ('' == $source) {
26
            return [];
27
        }
28
29
        return (array)eval(
30
            preg_replace('/^<\?php /', '', $source)
31
        );
32
    }
33
}
34