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

InsufficientData::fromOffset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 1
rs 9.6666
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 strlen;
9
10
final class InsufficientData extends RuntimeException implements MessagePackException
11
{
12
    /** @var mixed */
13
    private $value;
14
15 20
    public static function fromOffset(string $buffer, int $offset, int $expectedLength): self
16
    {
17 20
        $actualLength = strlen($buffer) - $offset;
18
19 20
        return new self(
20 20
            $buffer,
21
            "Not enough data to decode: expected length bytes ${expectedLength}, got ${actualLength}"
22
        );
23
    }
24
25
    public function getValue()
26
    {
27 20
        return $this->value;
28
    }
29
30
    private function __construct($value, string $message)
31
    {
32 20
        parent::__construct($message);
33
34 20
        $this->value = $value;
35 20
    }
36
}
37