Completed
Push — master ( f2b737...934162 )
by Lars
02:06
created

SerializerIgbinary::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace voku\cache;
6
7
/**
8
 * SerializerIgbinary: serialize / unserialize
9
 */
10
class SerializerIgbinary implements iSerializer
11
{
12
    /**
13
     * @var bool
14
     */
15
    public static $_exists_igbinary;
16
17
    /**
18
     * SerializerIgbinary constructor.
19
     */
20 60
    public function __construct()
21
    {
22 60
        self::$_exists_igbinary = (
23 60
            \function_exists('igbinary_serialize')
24
            &&
25 60
            \function_exists('igbinary_unserialize')
26
        );
27 60
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 27
    public function serialize($value)
33
    {
34 27
        if (self::$_exists_igbinary === true) {
35
            /** @noinspection PhpUndefinedFunctionInspection */
36
            return \igbinary_serialize($value);
37
        }
38
39
        // fallback
40 27
        return \serialize($value);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 20
    public function unserialize($value)
47
    {
48 20
        if (self::$_exists_igbinary === true) {
49
            /** @noinspection PhpUndefinedFunctionInspection */
50
            return \igbinary_unserialize($value);
51
        }
52
53
        // fallback
54 20
        return \unserialize($value);
55
    }
56
}
57