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

SerializerIgbinary::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 0
crap 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