TException::setHeaders()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace tinymeng\tools\exception;
3
4
use Exception;
5
6
/**
7
 * Class TException
8
 * @package tinymeng\tools\exception
9
 * @Author: TinyMeng <[email protected]>
10
 * @Created: 2020/8/17
11
 */
12
class TException extends \Exception
13
{
14
    /**
15
     * @var array
16
     */
17
    private $headers;
18
19
    public function __construct(int $statusCode, string $message = '', Exception $previous = null, array $headers = [], $code = 0)
20
    {
21
        $this->setHeaders($headers);
22
23
        /** message */
24
        if(empty($message)) $message = StatusCode::$status_code[$statusCode] ?? StatusCode::$status_code[StatusCode::COMMON_UNKNOWN];
25
        parent::__construct('ERROR tinymeng tools: '.$message, $code, $previous);
26
    }
27
28
    /**
29
     * @return array
30
     */
31
    public function getHeaders(): array
32
    {
33
        return $this->headers;
34
    }
35
36
    /**
37
     * @param array $headers
38
     * @return TException
39
     */
40
    public function setHeaders(array $headers): TException
41
    {
42
        $this->headers = $headers;
43
        return $this;
44
    }
45
}
46