Completed
Branch master (6bd7ca)
by Eugene
01:33
created

Extension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the rybakit/msgpack.php 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
namespace MessagePack\TypeTransformer;
13
14
use MessagePack\Packer;
15
16
abstract class Extension implements CanPack, CanUnpackExt
17
{
18
    private $type;
19
20
    public function __construct(int $type)
21
    {
22
        $this->type = $type;
23
    }
24
25
    public function getType() : int
26
    {
27
        return $this->type;
28
    }
29
30
    public function pack(Packer $packer, $value) : ?string
31
    {
32
        if (null === $data = $this->packExt($packer, $value)) {
33
            return null;
34
        }
35
36
        return $packer->packExt($this->type, $data);
37
    }
38
39
    abstract protected function packExt(Packer $packer, $value) : ?string;
40
}
41