Completed
Push — master ( b7f9bf...48ba4b )
by Lars
02:40
created

SerializerIgbinary   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
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 49
ccs 10
cts 13
cp 0.7692
rs 10
c 0
b 0
f 0

3 Methods

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