ResponseHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 0 Features 3
Metric Value
wmc 5
c 5
b 0
f 3
lcom 1
cbo 1
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B respond() 0 25 4
1
<?php
2
3
namespace Vinelab\Api;
4
5
/**
6
 * @author  Mahmoud Zalt <[email protected]>
7
 * @author  Abed Halawi <[email protected]>
8
 */
9
class ResponseHandler
10
{
11
    /**
12
     * @var Responder instance
13
     */
14
    protected $responder;
15
16
    /**
17
     * @param \Vinelab\Api\Responder $responder
18
     */
19
    public function __construct(Responder $responder)
20
    {
21
        $this->responder = $responder;
22
    }
23
24
    /**
25
     * Format a response into an elegant api manager response.
26
     *
27
     * @param array $data
28
     * @param null  $total
29
     * @param null  $page
30
     * @param null  $per_page
31
     * @param int   $status
32
     * @param array $headers
33
     * @param int   $options
34
     *
35
     * @internal param $arguments
36
     *
37
     * @return \Illuminate\Http\JsonResponse
38
     */
39
    public function respond(
40
        array $data,
41
        $total = null,
42
        $page = null,
43
        $per_page = null,
44
        $status = 200,
45
        $headers = [],
46
        $options = 0
47
    ) {
48
        $response = [
49
            'status' => $status,
50
        ];
51
        if (!is_null($total)) {
52
            $response['total'] = $total;
53
        }
54
        if (!is_null($page)) {
55
            $response['page'] = $page;
56
        }
57
        if (!is_null($per_page)) {
58
            $response['per_page'] = $per_page;
59
        }
60
        $response['data'] = $data;
61
62
        return $this->responder->respond($response, $status, $headers, $options);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->responder->respon...s, $headers, $options); of type Vinelab\Api\Responder|Illuminate\Http\JsonResponse adds the type Vinelab\Api\Responder to the return on line 62 which is incompatible with the return type documented by Vinelab\Api\ResponseHandler::respond of type Illuminate\Http\JsonResponse.
Loading history...
63
    }
64
}
65