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

SerializerIgbinary::serialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

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