Status   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
eloc 14
dl 0
loc 25
rs 10
c 2
b 1
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Provide\Error;
6
7
use BEAR\Resource\Exception\BadRequestException;
8
use Koriym\HttpConstants\StatusCode;
9
use RuntimeException;
10
use Throwable;
11
12
final class Status
13
{
14
    public int $code;
15
    public string $text;
16
17
    public function __construct(Throwable $e)
18
    {
19
        /** @var array<int, string> $text */
20
        $text = (new StatusCode())->statusText;
21
        if ($e instanceof BadRequestException) {
22
            $this->code = $e->getCode();
23
            $this->text = $text[$this->code] ?? '';
24
25
            return;
26
        }
27
28
        if ($e instanceof RuntimeException) {
29
            $this->code = 503;
30
            $this->text = $text[$this->code];
31
32
            return;
33
        }
34
35
        $this->code = 500;
36
        $this->text = $text[$this->code];
37
    }
38
}
39