Completed
Push — master ( c630a6...61819f )
by Alex
41:06 queued 37:44
created

InsufficientData::fromOffset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 9
ccs 0
cts 4
cp 0
crap 2
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
    public static function fromOffset(string $data, int $offset, int $expectedLength): self
16
    {
17
        $actualLength = strlen($data) - $offset;
18
19
        return new self(
20
            $buffer,
0 ignored issues
show
Bug introduced by
The variable $buffer does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
21
            "Not enough data to decode: expected length bytes ${expectedLength}, got ${actualLength}"
22
        );
23
    }
24
25
    public function getValue()
26
    {
27
        return $this->value;
28
    }
29
30
    private function __construct($value, string $message)
31
    {
32
        parent::__construct($message);
33
34
        $this->value = $value;
35
    }
36
}
37