UuidExtension::pack()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
1
<?php
2
3
/**
4
 * This file is part of the tarantool/client 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
declare(strict_types=1);
13
14
namespace Tarantool\Client\Packer\Extension;
15
16
use MessagePack\BufferUnpacker;
17
use MessagePack\Extension;
18
use MessagePack\Packer;
19
use Symfony\Component\Uid\Uuid;
20
21
final class UuidExtension implements Extension
22
{
23
    private const TYPE = 2;
24
25 155
    public function getType() : int
26
    {
27 155
        return self::TYPE;
28
    }
29
30 11
    public function pack(Packer $packer, $value) : ?string
31
    {
32 11
        if (!$value instanceof Uuid) {
33
            return null;
34
        }
35
36 11
        return $packer->packExt(self::TYPE, $value->toBinary());
37
    }
38
39
    /**
40
     * @return Uuid
41
     */
42 11
    public function unpackExt(BufferUnpacker $unpacker, int $extLength)
43
    {
44 11
        return Uuid::fromString($unpacker->read($extLength));
45
    }
46
}
47