Passed
Push — master ( 40a1ef...d411b0 )
by Jonathan
02:44
created

AbstractException::getStatusCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Ctw\Http\HttpException;
5
6
use Ctw\Http\HttpStatus;
7
use RuntimeException;
8
use Throwable;
9
10
abstract class AbstractException extends RuntimeException implements HttpExceptionInterface
11
{
12
    protected int   $statusCode;
13
14
    protected array $headers;
15
16 242
    public function __construct(string $message = null, Throwable $previous = null, array $headers = [], int $code = 0)
17
    {
18 242
        $this->setHeaders($headers);
19
20 242
        if (empty($message)) {
21 162
            $statusCode = $this->getStatusCode();
22 162
            $entity     = (new HttpStatus($statusCode))->get();
23 162
            $message    = sprintf('%d %s', $entity->statusCode, $entity->name);
24
        }
25
26 242
        parent::__construct($message, $code, $previous);
27 242
    }
28
29 242
    public function getStatusCode(): int
30
    {
31 242
        return $this->statusCode;
32
    }
33
34 80
    public function setStatusCode(int $statusCode): self
35
    {
36 80
        $this->statusCode = $statusCode;
37
38 80
        return $this;
39
    }
40
41 160
    public function getHeaders(): array
42
    {
43 160
        return $this->headers;
44
    }
45
46 242
    public function setHeaders(array $headers): self
47
    {
48 242
        $this->headers = $headers;
49
50 242
        return $this;
51
    }
52
}
53