Test Setup Failed
Push — master ( 9ec3c0...c630a6 )
by Alex
41:24
created

UnknownByteHeader::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace MessagePack\Exception;
5
6
use MessagePack\MessagePackException;
7
use RuntimeException;
8
use function dechex;
9
10
final class UnknownByteHeader extends RuntimeException implements MessagePackException
11
{
12
    /** @var mixed */
13
    private $value;
14
15 1
    public static function fromOffset(int $value, int $offset): self
16
    {
17 1
        $byte = dechex($value);
18
19 1
        return new self(
20 1
            $value,
21
            "Can't decode data with byte-header 0x${byte} in position ${offset}"
22
        );
23
    }
24
25
    public function getValue()
26
    {
27
        return $this->value;
28
    }
29
30
    private function __construct($value, string $message)
31
    {
32 1
        parent::__construct($message);
33
34 1
        $this->value = $value;
35 1
    }
36
}
37