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

UnknownByteHeader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromOffset() 0 9 1
A getValue() 0 4 1
A __construct() 0 6 1
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