Total Complexity | 4 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class ApiResponse |
||
8 | { |
||
9 | /** |
||
10 | * @var array |
||
11 | */ |
||
12 | private $data; |
||
13 | |||
14 | /** |
||
15 | * @var bool |
||
16 | */ |
||
17 | private $status; |
||
18 | |||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | private $responseCode; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $message; |
||
28 | |||
29 | 5 | private function __construct($data, $status, $responseCode, $message) |
|
30 | { |
||
31 | 5 | $this->data = $data; |
|
32 | 5 | $this->status = $status; |
|
33 | 5 | $this->responseCode = $responseCode; |
|
34 | 5 | $this->message = $message ?: ResponseCode::$statusTexts[$responseCode]; |
|
35 | 5 | } |
|
36 | |||
37 | /** |
||
38 | * setup, build and return the response. |
||
39 | * |
||
40 | * @param array $data An array of returned data |
||
41 | * @param int $status true or false for the operation status |
||
42 | * @param int $responseCode the Http response code |
||
43 | * @param string $message response message |
||
44 | * |
||
45 | * @return \Illuminate\Http\Response |
||
46 | */ |
||
47 | 5 | public static function send($data, $status = true, $responseCode = ResponseCode::HTTP_OK, string $message = '') |
|
48 | { |
||
49 | 5 | return (new static($data, $status, $responseCode, $message))->buildResponse(); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * build the response. |
||
54 | * |
||
55 | * @return \Illuminate\Http\Response |
||
56 | */ |
||
57 | 5 | private function buildResponse() |
|
65 | } |
||
66 | } |
||
67 |