EmailExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 31
rs 10

4 Methods

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