Completed
Push — master ( e0e79a...37618e )
by Lars
02:56
created

SerializerIgbinary   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 81.82%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 53
ccs 9
cts 11
cp 0.8182
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A serialize() 0 10 2
A unserialize() 0 10 2
1
<?php
2
3
namespace voku\cache;
4
5
/**
6
 * SerializerIgbinary: serialize / unserialize
7
 *
8
9
 * @package   voku\cache
10
 */
11
class SerializerIgbinary implements iSerializer
12
{
13
14
  /**
15
   * @var bool
16
   */
17
  public static $_exists_igbinary;
18
19
  /**
20
   * SerializerIgbinary constructor.
21
   */
22 6
  public function __construct()
23
  {
24 6
    self::$_exists_igbinary = (function_exists('igbinary_serialize') && function_exists('igbinary_unserialize'));
25 6
  }
26
27
  /**
28
   * serialize
29
   *
30
   * @param mixed $value
31
   *
32
   * @return string
33
   */
34 3
  public function serialize($value)
35
  {
36 3
    if (self::$_exists_igbinary === true) {
37
      /** @noinspection PhpUndefinedFunctionInspection */
38
      return igbinary_serialize($value);
39
    } else {
40
      // fallback
41 3
      return serialize($value);
42
    }
43
  }
44
45
  /**
46
   * unserialize
47
   *
48
   * @param string $value
49
   *
50
   * @return mixed
51
   */
52 4
  public function unserialize($value)
53
  {
54 4
    if (self::$_exists_igbinary === true) {
55
      /** @noinspection PhpUndefinedFunctionInspection */
56
      return igbinary_unserialize($value);
57
    } else {
58
      // fallback
59 4
      return unserialize($value);
60
    }
61
  }
62
63
}
64