ElfSundae /
laravel-api
| 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
|
|||
| 75 | { |
||
| 76 | return $this->getResponse(); |
||
| 77 | } |
||
| 78 | } |
||
| 79 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.