TException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 32
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A setHeaders() 0 4 1
A getHeaders() 0 3 1
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