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

UnsupportedType::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
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 get_class;
9
use function gettype;
10
use function is_object;
11
12
final class UnsupportedType extends RuntimeException implements MessagePackException
13
{
14
    /** @var mixed */
15
    private $value;
16
17 3
    public static function withValue($value): self
18
    {
19 3
        $type = gettype($value);
20 3
        $spec = $value;
21
22 3
        if (is_object($spec)) {
23 2
            $spec = get_class($spec);
24
        }
25
26
        return new self($value, "Unsupported type: ${type} (${spec})");
27
    }
28
29
    public function getValue()
30
    {
31 3
        return $this->value;
32
    }
33
34
    private function __construct($value, string $message)
35
    {
36 3
        parent::__construct($message);
37
38 3
        $this->value = $value;
39 3
    }
40
}
41