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 13
CRAP Score 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 11
c 1
b 1
f 0
dl 0
loc 20
ccs 13
cts 13
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
    /** @var int */
15
    public $code;
16
17
    /** @var string */
18
    public $text;
19
20
    public function __construct(Throwable $e)
21
    {
22 6
        /** @var array<int, string> $text */
23
        $text = (new StatusCode())->statusText;
24 6
        if ($e instanceof BadRequestException) {
25 6
            $this->code = $e->getCode();
26 2
            $this->text = $text[$this->code] ?? '';
27 2
28
            return;
29 2
        }
30
31 4
        if ($e instanceof RuntimeException) {
32 1
            $this->code = 503;
33 1
            $this->text = $text[$this->code];
34
35 1
            return;
36
        }
37 3
38 3
        $this->code = 500;
39 3
        $this->text = $text[$this->code];
40
    }
41
}
42