Msgpack   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 32
ccs 9
cts 9
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 4 1
A unserialize() 0 4 1
A isSerialized() 0 8 2
1
<?php
2
3
/**
4
 *
5
 * This file is part of the Apix Project.
6
 *
7
 * (c) Franck Cassedanne <franck at ouarz.net>
8
 *
9
 * @license     http://opensource.org/licenses/BSD-3-Clause  New BSD License
10
 *
11
 */
12
13
namespace Apix\Cache\Serializer;
14
15
/**
16
 * MessagePack - a light cross-language binary serializer.
17
 * Serializes data using the Msgpack extension.
18
 * @see https://github.com/msgpack/msgpack-php
19
 *
20
 * @author Franck Cassedanne <franck at ouarz.net>
21
 */
22
class Msgpack implements Adapter
23
{
24
25
    /**
26
     * {@inheritdoc}
27 136
     */
28
    public function serialize($data)
29 136
    {
30
        return \msgpack_pack($data);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35 68
     */
36
    public function unserialize($str)
37 68
    {
38
        return \msgpack_unpack($str);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43 68
     */
44
    public function isSerialized($str)
45 68
    {
46 34
        if (!is_string($str)) {
47
            return false;
48
        }
49 68
50
        return (boolean) !is_integer( @\msgpack_unpack($str) );
51
    }
52
53
}
54