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

EmailTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A pack() 0 5 2
A unpack() 0 3 1
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
use MessagePack\BufferUnpacker;
15
use MessagePack\Packer;
16
use MessagePack\TypeTransformer\Packable;
17
use MessagePack\TypeTransformer\Unpackable;
18
19
final class EmailTransformer implements Packable, Unpackable
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
20
{
21
    private $type;
22
23
    public function __construct(int $type)
24
    {
25
        $this->type = $type;
26
    }
27
28
    public function getType() : int
29
    {
30
        return $this->type;
31
    }
32
33
    public function pack(Packer $packer, $value) : ?string
34
    {
35
        return $value instanceof Email
36
            ? $packer->packStr($value->toString())
37
            : null;
38
    }
39
40
    public function unpack(BufferUnpacker $unpacker, int $extLength) : Email
41
    {
42
        return new Email($unpacker->unpackStr());
43
    }
44
}
45