Passed
Push — master ( 9013bb...125cf1 )
by Kirill
03:56
created

ClientException::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 4
nc 4
nop 3
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Http\Exception;
13
14
/**
15
 * Generic client driven http exception.
16
 */
17
class ClientException extends HttpException
18
{
19
    /**
20
     * Most common codes.
21
     */
22
    public const BAD_DATA = 400;
23
    public const UNAUTHORIZED = 401;
24
    public const FORBIDDEN = 403;
25
    public const NOT_FOUND = 404;
26
    public const ERROR = 500;
27
28
    /**
29
     * Code and message positions are reverted.
30
     *
31
     * @param int $code
32
     * @param string $message
33
     * @param \Throwable|null $previous
34
     */
35
    public function __construct(?int $code = null, string $message = '', ?\Throwable $previous = null)
36
    {
37
        if (empty($code) && empty($this->code)) {
38
            $code = self::BAD_DATA;
39
        }
40
41
        if (empty($message)) {
42
            $message = "Http Error - {$code}";
43
        }
44
45
        parent::__construct($message, $code, $previous);
46
    }
47
}
48