Completed
Push — master ( 67b201...64a3e6 )
by Lars
02:31 queued 11s
created

SerializerIgbinary   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 76.92%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 47
ccs 10
cts 13
cp 0.7692
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 10 2
A unserialize() 0 10 2
A __construct() 0 8 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 33
    public function __construct()
21
    {
22
        self::$_exists_igbinary = (
23 33
            \function_exists('igbinary_serialize')
24
            &&
25 33
            \function_exists('igbinary_unserialize')
26
        );
27 33
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 18
    public function serialize($value)
33
    {
34 18
        if (self::$_exists_igbinary === true) {
35
            /** @noinspection PhpUndefinedFunctionInspection */
36
            return \igbinary_serialize($value);
37
        }
38
39
        // fallback
40 18
        return \serialize($value);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 17
    public function unserialize($value)
47
    {
48 17
        if (self::$_exists_igbinary === true) {
49
            /** @noinspection PhpUndefinedFunctionInspection */
50
            return \igbinary_unserialize($value);
51
        }
52
53
        // fallback
54 17
        return \unserialize($value);
55
    }
56
}
57