JsonResponses::jsonResponseError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 5
crap 1
1
<?php namespace Arcanedev\LaravelApiHelper\Traits;
2
3
/**
4
 * Class     JsonResponses
5
 *
6
 * @package  Arcanedev\LaravelApiHelper\Traits
7
 * @author   ARCANEDEV <[email protected]>
8
 */
9
trait JsonResponses
10
{
11
    /* -----------------------------------------------------------------
12
     |  Main Methods
13
     | -----------------------------------------------------------------
14
     */
15
16
    /**
17
     * Get the json response instance.
18
     *
19
     * @return \Arcanedev\LaravelApiHelper\Contracts\Http\JsonResponse
20
     */
21 16
    public function jsonResponse()
22
    {
23 16
        return json_response();
24
    }
25
26
    /**
27
     * Respond with a success response.
28
     *
29
     * @param  array   $data
30
     * @param  int     $status
31
     * @param  string  $code
32
     * @param  array   $headers
33
     * @param  int     $options
34
     *
35
     * @return \Illuminate\Http\JsonResponse
36
     */
37 12
    public function jsonResponseSuccess(array $data = [], $status = 200, $code = 'success', array $headers = [], $options = 0)
38
    {
39 12
        return $this->jsonResponse()->success($data, $status, $code, $headers, $options);
40
    }
41
42
    /**
43
     * Respond with an error response.
44
     *
45
     * @param  array   $data
46
     * @param  int     $status
47
     * @param  string  $code
48
     * @param  array   $headers
49
     * @param  int     $options
50
     *
51
     * @return \Illuminate\Http\JsonResponse
52
     */
53 4
    public function jsonResponseError(array $data = [], $status = 400, $code = 'error', array $headers = [], $options = 0)
54
    {
55 4
        return $this->jsonResponse()->error($data, $status, $code, $headers, $options);
56
    }
57
}
58