Completed
Push — master ( a65293...0f75be )
by Eugene
09:52
created

UuidExtension::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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\Packer;
18
use MessagePack\TypeTransformer\Extension;
19
use Symfony\Component\Uid\Uuid;
20
21
class UuidExtension implements Extension
22
{
23
    private const TYPE = 2;
24
25
    public function getType() : int
26
    {
27
        return self::TYPE;
28
    }
29
30
    /**
31
     * @param object $value
32
     */
33
    public function pack(Packer $packer, $value) : ?string
34
    {
35
        if (!$value instanceof Uuid) {
36
            return null;
37
        }
38
39
        return $packer->packExt(self::TYPE, $value->toBinary());
40
    }
41
42
    /**
43
     * @return Uuid
44
     */
45
    public function unpackExt(BufferUnpacker $unpacker, int $extLength)
46
    {
47
        return Uuid::fromString($unpacker->read($extLength));
48
    }
49
}
50