Completed
Push — 1.x ( ce34cb...ebc2f4 )
by Akihito
02:21
created

Status::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 1
1
<?php
2
/**
3
 * This file is part of the BEAR.Package package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Package\Provide\Error;
8
9
use BEAR\Resource\Exception\BadRequestException;
10
use Koriym\HttpConstants\StatusCode;
11
12
final class Status
13
{
14
    /**
15
     * @var int
16
     */
17
    public $code;
18
19
    /**
20
     * @var string
21
     */
22
    public $text;
23
24
    public function __construct(\Exception $e)
25
    {
26
        $text = (new StatusCode)->statusText;
27
        if ($e instanceof BadRequestException) {
28
            $this->code = $e->getCode();
29
            $this->text = $text[$this->code];
30
31
            return;
32
        }
33
        if ($e instanceof \RuntimeException) {
34
            $this->code = 503;
35
            $this->text = $text[$this->code];
36
37
            return;
38
        }
39
        $this->code = 500;
40
        $this->text = $text[$this->code];
41
    }
42
}
43