EmailExtension::getType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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 App;
15
16
use MessagePack\BufferUnpacker;
17
use MessagePack\Extension;
18
use MessagePack\Packer;
19
20
final class EmailExtension implements Extension
21
{
22
    private $type;
23
24
    public function __construct(int $type)
25
    {
26
        $this->type = $type;
27
    }
28
29
    public function getType() : int
30
    {
31
        return $this->type;
32
    }
33
34
    /**
35
     * @param mixed $value
36
     */
37
    public function pack(Packer $packer, $value) : ?string
38
    {
39
        if (!$value instanceof Email) {
40
            return null;
41
        }
42
43
        return $packer->packExt($this->type,
44
            $packer->packStr($value->toString())
45
        );
46
    }
47
48
    public function unpackExt(BufferUnpacker $unpacker, int $extLength) : Email
49
    {
50
        return new Email($unpacker->unpackStr());
51
    }
52
}
53