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

EmailTransformer::pack()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
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