UnsupportedResponseTypeException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A inferType() 0 10 2
A fromType() 0 5 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