MessagePack::getBuiltInExtensions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of the rybakit/msgpack.php package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace MessagePack;
13
14
use MessagePack\Exception\InvalidOptionException;
15
use MessagePack\Exception\PackingFailedException;
16
use MessagePack\Exception\UnpackingFailedException;
17
use MessagePack\Extension\TimestampExtension;
18
19
final class MessagePack
20
{
21
    /** @var Extension[]|null */
22
    private static $extensions;
23
24
    /**
25
     * @codeCoverageIgnore
26
     */
27
    private function __construct()
28
    {
29
    }
30
31
    /**
32
     * @param mixed $value
33
     * @param PackOptions|int|null $options
34
     *
35
     * @throws InvalidOptionException
36
     * @throws PackingFailedException
37
     */
38 3
    public static function pack($value, $options = null) : string
39
    {
40 3
        return (new Packer($options, self::getBuiltInExtensions()))->pack($value);
41
    }
42
43
    /**
44
     * @param UnpackOptions|int|null $options
45
     *
46
     * @throws InvalidOptionException
47
     * @throws UnpackingFailedException
48
     *
49
     * @return mixed
50
     */
51 3
    public static function unpack(string $data, $options = null)
52
    {
53 3
        return (new BufferUnpacker($data, $options, self::getBuiltInExtensions()))->unpack();
54
    }
55
56 6
    private static function getBuiltInExtensions() : array
57
    {
58 6
        return self::$extensions ?? self::$extensions = [
59 6
            new TimestampExtension(),
60
        ];
61
    }
62
}
63