Status::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 20
ccs 10
cts 10
cp 1
rs 9.9
cc 3
nc 3
nop 1
crap 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 6
            $this->code = $e->getCode();
23
            $this->text = $text[$this->code] ?? '';
24 6
25 6
            return;
26 2
        }
27 2
28
        if ($e instanceof RuntimeException) {
29 2
            $this->code = 503;
30
            $this->text = $text[$this->code];
31 4
32 1
            return;
33 1
        }
34
35 1
        $this->code = 500;
36
        $this->text = $text[$this->code];
37 3
    }
38
}
39