AbstractException::getHeaders()   A
last analyzed

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 160
    public function __construct(
15
        string $message = '',
16
        Throwable $previous = null,
17
        protected array $headers = [],
18
        int $code = 0
19
    ) {
20 160
        if ('' === $message) {
21 80
            $statusCode = $this->getStatusCode();
22 80
            $entity     = (new HttpStatus($statusCode))->get();
23 80
            $message    = sprintf('%d %s', $entity->statusCode, $entity->name);
24
        }
25
26 160
        parent::__construct($message, $code, $previous);
27
    }
28
29 160
    public function getStatusCode(): int
30
    {
31 160
        return $this->statusCode;
32
    }
33
34 80
    public function getHeaders(): array
35
    {
36 80
        return $this->headers;
37
    }
38
}
39