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

UuidExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3

3 Methods

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