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

UnsupportedType::withValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
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