BaseException   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getError() 0 3 1
A toString() 0 6 2
A getDescription() 0 3 1
A getStatusCode() 0 3 1
A __construct() 0 9 1
1
<?php
2
3
namespace Bcl\EasyPdfCloud\Exception;
4
5
use Exception;
6
use Bcl\EasyPdfCloud\StringUtils;
7
8
abstract class BaseException extends Exception
9
{
10
    /**
11
     * @var int
12
     */
13
    protected $statusCode;
14
15
    /**
16
     * @var string
17
     */
18
    protected $error;
19
20
    /**
21
     * @var string
22
     */
23
    protected $description;
24
25
    /**
26
     * BaseException constructor.
27
     *
28
     * @param int $statusCode
29
     * @param string $error
30
     * @param string $description
31
     * @param int $code
32
     * @param Exception|null $previous
33
     */
34
    public function __construct(int $statusCode, string $error, string $description, $code = 0, Exception $previous = null)
35
    {
36
        $message = $this->toString($statusCode, $error, $description);
37
38
        parent::__construct($message, $code, $previous);
39
40
        $this->statusCode = $statusCode;
41
        $this->error = $error;
42
        $this->description = $description;
43
    }
44
45
    /**
46
     * @return int
47
     */
48
    public function getStatusCode()
49
    {
50
        return $this->statusCode;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getError(): string
57
    {
58
        return $this->error;
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getDescription(): string
65
    {
66
        return $this->description;
67
    }
68
69
    /**
70
     * @param string $statusCode
71
     * @param string $error
72
     * @param string $description
73
     *
74
     * @return string
75
     */
76
    protected function toString(int $statusCode, string $error, string $description): string
77
    {
78
        $string = (StringUtils::length($description) > 0 ? $description : $error);
79
        $string .= ' (HTTP status code: ' . $statusCode . ')';
80
81
        return $string;
82
    }
83
}