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

SerializerIgbinary::serialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

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