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

InsufficientData   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 0
cts 8
cp 0
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 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