Completed
Push — api/develop ( 11afe9...d1fbdd )
by Bertrand
04:59
created

BaseController::_response()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 3
crap 2
1
<?php
2
3
/**
4
 * This file is part of the HRis Software package.
5
 *
6
 * HRis - Human Resource and Payroll System
7
 *
8
 * @link    http://github.com/HB-Co/HRis
9
 */
10
namespace HRis\Api\Controllers;
11
12
use Dingo\Api\Routing\Helpers;
13
use Illuminate\Routing\Controller;
14
use Swagger\Annotations as SWG;
15
16
/**
17
 * @SWG\Swagger(
18
 *     schemes={"https", "http"},
19
 *     host="api.hris.dev",
20
 *     basePath="/api",
21
 *     @SWG\Info(
22
 *         version="1.0.0",
23
 *         title="HRis",
24
 *         description="Human Resource and Payroll System",
25
 *         @SWG\Contact(
26
 *             email="[email protected]"
27
 *         )
28
 *     ),
29
 *     @SWG\ExternalDocumentation(
30
 *         description="Fork HRis on GitHub",
31
 *         url="https://github.com/bkintanar/HRis"
32
 *     )
33
 * )
34
 */
35
class BaseController extends Controller
36
{
37
    use Helpers;
38
39
    public $data = [];
40
41
    /**
42
     * Standard response for any request.
43
     *
44
     * @param        $status_code
45
     * @param string $message
46
     * @param array  $data
47
     *
48
     * @return mixed
49
     *
50
     * @author Bertrand Kintanar <[email protected]>
51
     */
52 64
    public function _response($status_code, $message = '', $data = [])
53
    {
54 64
        $response = [];
55 64
        $response['message']     = $message;
56 64
        $response['status_code'] = $status_code;
57
58 64
        if (!empty($data)) {
59 58
            $response = array_merge($response, $data);
60 58
        }
61
62 64
        return $this->response->withArray($response)->statusCode($status_code);
63
    }
64
}
65