UnsupportedResponseTypeException::inferType()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Router\Exceptions;
6
7
use RuntimeException;
8
9
use function get_class;
10
use function gettype;
11
12
final class UnsupportedResponseTypeException extends RuntimeException
13
{
14 4
    public static function fromType(mixed $var): self
15
    {
16 4
        $type = self::inferType($var);
17
18 4
        return new self("Unsupported response type '{$type}'. Must be a string or implement Stringable interface.");
19
    }
20
21 4
    private static function inferType(mixed $var): string
22
    {
23 4
        $type = gettype($var);
24
25 4
        if ($type === 'object') {
26
            /** @var object $var */
27 1
            return get_class($var);
28
        }
29
30 3
        return $type;
31
    }
32
}
33