Passed
Pull Request — master (#37)
by Eugene
03:09
created

EmailTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 8
dl 0
loc 26
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A unpack() 0 3 1
A pack() 0 7 2
A __construct() 0 3 1
A getType() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Tarantool Client package.
7
 *
8
 * (c) Eugene Leonovich <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace App;
15
16
use MessagePack\BufferUnpacker;
17
use MessagePack\Packer;
18
use MessagePack\TypeTransformer\Packable;
19
use MessagePack\TypeTransformer\Unpackable;
20
21
final class EmailTransformer implements Packable, Unpackable
22
{
23
    private $type;
24
25
    public function __construct(int $type)
26
    {
27
        $this->type = $type;
28
    }
29
30
    public function getType() : int
31
    {
32
        return $this->type;
33
    }
34
35
    public function pack(Packer $packer, $value) : ?string
36
    {
37
        if (!$value instanceof Email) {
38
            return null;
39
        }
40
41
        return $packer->packExt($this->type, $packer->packStr($value->toString()));
42
    }
43
44
    public function unpack(BufferUnpacker $unpacker, int $extLength) : Email
45
    {
46
        return new Email($unpacker->unpackStr());
47
    }
48
}
49