Completed
Push — master ( 94f381...097ee4 )
by Lars
83:13
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
 * @package voku\cache
11
 */
12
class SerializerIgbinary implements iSerializer
13
{
14
15
  /**
16
   * @var bool
17
   */
18
  public static $_exists_igbinary;
19
20
  /**
21
   * SerializerIgbinary constructor.
22
   */
23 22
  public function __construct()
24
  {
25
    self::$_exists_igbinary = (
26 22
        \function_exists('igbinary_serialize')
27
        &&
28 22
        \function_exists('igbinary_unserialize')
29
    );
30 22
  }
31
32
  /**
33
   * @inheritdoc
34
   */
35 12
  public function serialize($value)
36
  {
37 12
    if (self::$_exists_igbinary === true) {
38
      /** @noinspection PhpUndefinedFunctionInspection */
39
      return igbinary_serialize($value);
40
    }
41
42
    // fallback
43 12
    return serialize($value);
44
  }
45
46
  /**
47
   * @inheritdoc
48
   */
49 11
  public function unserialize($value)
50
  {
51 11
    if (self::$_exists_igbinary === true) {
52
      /** @noinspection PhpUndefinedFunctionInspection */
53
      return igbinary_unserialize($value);
54
    }
55
56
    // fallback
57 11
    return unserialize($value);
58
  }
59
60
}
61