Completed
Push — master ( bdd024...14352f )
by Elf
04:10
created

ApiResponseException::actionFailureException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ElfSundae\Laravel\Api\Exceptions;
4
5
use RuntimeException;
6
use ElfSundae\Laravel\Api\ApiResponse;
7
8
class ApiResponseException extends RuntimeException
9
{
10
    /**
11
     * The underlying response instance.
12
     *
13
     * @var \ElfSundae\Laravel\Api\ApiResponse
14
     */
15
    protected $response;
16
17
    /**
18
     * Create a new exception instance.
19
     *
20
     * @param  mixed  $data
21
     * @param  int  $code
22
     * @param  array  $headers
23
     * @param  int  $options
24
     */
25
    public function __construct($data = null, $code = -1, $headers = [], $options = 0)
26
    {
27
        $this->response = new ApiResponse($data, $code, $headers, $options);
28
    }
29
30
    /**
31
     * Thrown when the user input is invalid.
32
     *
33
     * @param  mixed  $data
34
     * @param  int  $code
35
     * @param  array  $headers
36
     * @param  int  $options
37
     * @return static
38
     */
39
    public static function invalidInput($data = 'Invalid Input', $code = 421, $headers = [], $options = 0)
40
    {
41
        return new static($data, $code, $headers, $options);
42
    }
43
44
    /**
45
     * Thrown when action failed.
46
     *
47
     * @param  mixed  $data
48
     * @param  int  $code
49
     * @param  array  $headers
50
     * @param  int  $options
51
     * @return static
52
     */
53
    public static function actionFailure($data = 'Action Failure', $code = 470, $headers = [], $options = 0)
54
    {
55
        return new static($data, $code, $headers, $options);
56
    }
57
58
    /**
59
     * Get the underlying response instance.
60
     *
61
     * @return \ElfSundae\Laravel\Api\ApiResponse
62
     */
63
    public function getResponse()
64
    {
65
        return $this->response;
66
    }
67
68
    /**
69
     * Render the exception into an HTTP response.
70
     *
71
     * @param  \Illuminate\Http\Request  $request
72
     * @return \Illuminate\Http\Response
73
     */
74
    public function render($request)
75
    {
76
        return $this->getResponse();
77
    }
78
}
79