Completed
Push — master ( 5cfb46...2936f6 )
by Lars
01:39
created

SerializerIgbinary   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 84.62%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 49
ccs 11
cts 13
cp 0.8462
rs 10
c 1
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 11
  public function __construct()
24
  {
25 11
    self::$_exists_igbinary = (
26 11
        \function_exists('igbinary_serialize')
27
        &&
28 11
        \function_exists('igbinary_unserialize')
29
    );
30 11
  }
31
32
  /**
33
   * @inheritdoc
34
   */
35 6
  public function serialize($value)
36
  {
37 6
    if (self::$_exists_igbinary === true) {
38
      /** @noinspection PhpUndefinedFunctionInspection */
39
      return igbinary_serialize($value);
40
    }
41
42
    // fallback
43 6
    return serialize($value);
44
  }
45
46
  /**
47
   * @inheritdoc
48
   */
49 7
  public function unserialize($value)
50
  {
51 7
    if (self::$_exists_igbinary === true) {
52
      /** @noinspection PhpUndefinedFunctionInspection */
53
      return igbinary_unserialize($value);
54
    }
55
56
    // fallback
57 7
    return unserialize($value);
58
  }
59
60
}
61