Completed
Push — master ( 94f5e8...a88b9e )
by Lars
01:57 queued 11s
created

SerializerDefault   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 44
ccs 8
cts 11
cp 0.7272
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 4 1
A getName() 0 4 1
A unserialize() 0 9 2
A setUnserializeOptions() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace voku\cache;
6
7
/**
8
 * SerializerDefault: simple serialize / unserialize
9
 */
10
class SerializerDefault implements iSerializer
11
{
12
    /**
13
     * @var array|null
14
     */
15
    private $unserialize_options;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 20
    public function serialize($value)
21
    {
22 20
        return \serialize($value);
23
    }
24
25
    /**
26
     * @return string
27
     */
28
    public function getName(): string
29
    {
30
        return 'default';
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 18
    public function unserialize($value)
37
    {
38 18
        if ($this->unserialize_options !== null) {
39 18
            return \unserialize($value, $this->unserialize_options);
40
        }
41
42
        /** @noinspection UnserializeExploitsInspection */
43
        return \unserialize($value);
44
    }
45
46
    /**
47
     * @param array $options
48
     */
49 38
    public function setUnserializeOptions(array $options)
50
    {
51 38
        $this->unserialize_options = $options;
52 38
    }
53
}
54