Completed
Push — master ( b96965...99f77d )
by Lars
02:12
created

SerializerDefault   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 36
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 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 null|array
14
     */
15
    private $unserialize_options;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 23
    public function serialize($value)
21
    {
22 23
        return \serialize($value);
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 21
    public function unserialize($value)
29
    {
30 21
        if ($this->unserialize_options !== null) {
31 21
            return \unserialize($value, $this->unserialize_options);
32
        }
33
34
        /** @noinspection UnserializeExploitsInspection */
35
        return \unserialize($value);
36
    }
37
38
    /**
39
     * @param array $options
40
     */
41 44
    public function setUnserializeOptions(array $options)
42
    {
43 44
        $this->unserialize_options = $options;
44 44
    }
45
}
46