UuidExtension::getType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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