Passed
Branch related-record-fixes (1a5bc9)
by Alex
02:41
created

HttpException::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
1
<?php
2
3
namespace Huntie\JsonApi\Exceptions;
4
5
use Huntie\JsonApi\Support\JsonApiErrors;
6
use Illuminate\Http\Response;
7
use Illuminate\Http\Exception\HttpResponseException;
8
9
class HttpException extends HttpResponseException
10
{
11
    use JsonApiErrors;
12
13
    /**
14
     * Create a new HttpException instance.
15
     *
16
     * @param string            $message  The message for this exception
17
     * @param Response|int|null $response The response object or HTTP status code send to the client
18
     */
19
    public function __construct($message, $response = null)
20
    {
21
        if (is_null($response)) {
22
            $response = $this->error(Response::HTTP_BAD_REQUEST, $message);
23
        } else if (is_int($response)) {
24
            $response = $this->error($response, $message);
25
        }
26
27
        parent::__construct($response);
28
    }
29
}
30