HttpException::errorCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Flugg\Responder\Exceptions\Http;
4
5
use Symfony\Component\HttpKernel\Exception\HttpException as BaseHttpException;
6
7
/**
8
 * An abstract exception responsible for holding error response data.
9
 *
10
 * @package flugger/laravel-responder
11
 * @author  Alexander Tømmerås <[email protected]>
12
 * @license The MIT License
13
 */
14
abstract class HttpException extends BaseHttpException
15
{
16
    /**
17
     * An HTTP status code.
18
     *
19
     * @var int
20
     */
21
    protected $status = 500;
22
23
    /**
24
     * An error code.
25
     *
26
     * @var string|null
27
     */
28
    protected $errorCode = null;
29
30
    /**
31
     * An error message.
32
     *
33
     * @var string|null
34
     */
35
    protected $message = null;
36
37
    /**
38
     * Additional error data.
39
     *
40
     * @var array|null
41
     */
42
    protected $data = null;
43
44
    /**
45
     * Attached headers.
46
     *
47
     * @var array
48
     */
49
    protected $headers = [];
50
51
    /**
52
     * Construct the exception class.
53
     *
54
     * @param string|null $message
55
     * @param array|null  $headers
56
     */
57 10
    public function __construct(string $message = null, array $headers = null)
58
    {
59 10
        parent::__construct($this->status, $message ?? $this->message, null, $headers ?? $this->headers);
60 10
    }
61
62
    /**
63
     * Retrieve the HTTP status code,
64
     *
65
     * @return int
66
     */
67 1
    public function statusCode(): int
68
    {
69 1
        return $this->status;
70
    }
71
72
    /**
73
     * Retrieve the error code.
74
     *
75
     * @return string|null
76
     */
77 1
    public function errorCode()
78
    {
79 1
        return $this->errorCode;
80
    }
81
82
    /**
83
     * Retrieve the error message.
84
     *
85
     * @return string|null
86
     */
87 1
    public function message()
88
    {
89 1
        return $this->message ?: null;
90
    }
91
92
    /**
93
     * Retrieve additional error data.
94
     *
95
     * @return array|null
96
     */
97 1
    public function data()
98
    {
99 1
        return $this->data;
100
    }
101
102
    /**
103
     * Retrieve attached headers.
104
     *
105
     * @return array|null
106
     */
107 1
    public function headers()
108
    {
109 1
        return $this->headers;
110
    }
111
}
112