UuidExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 24
ccs 7
cts 8
cp 0.875
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A pack() 0 7 2
A unpackExt() 0 3 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