ApiResponseException::getResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

74
    public function render(/** @scrutinizer ignore-unused */ $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
    {
76
        return $this->getResponse();
77
    }
78
}
79