Passed
Push — master ( 8016ac...3325dd )
by Iman
05:45 queued 51s
created

ApiResponder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 10 4
A makeResult() 0 12 2
1
<?php
2
3
namespace Crocodicstudio\Crudbooster\Modules\ApiGeneratorModule\ApiController;
4
5
class ApiResponder
6
{
7
    /**
8
     * @param $status
9
     * @param $msg
10
     * @return array
11
     */
12
    public static function makeResult($status, $msg)
13
    {
14
        $result = [
15
            'api_status'=> $status,
16
            'api_message'=> $msg,
17
        ];
18
19
        if (cbGetsetting('api_debug_mode') == 'true') {
20
            $result['api_authorization'] = 'You are in debug mode !';
21
        }
22
23
        return $result;
24
    }
25
26
    /**
27
     * @param $result
28
     * @param $posts
29
     * @param $ctrl
30
     * @return mixed
31
     */
32
    public static function send($result, $posts, $ctrl)
33
    {
34
        $ctrl->hookAfter($posts, $result);
35
        $result['api_status'] = $ctrl->hook_api_status ?: $result['api_status'];
36
        $result['api_message'] = $ctrl->hook_api_message ?: $result['api_message'];
37
38
        if (cbGetsetting('api_debug_mode') == 'true') {
39
            $result['api_authorization'] = 'You are in debug mode !';
40
        }
41
        respondWith()->json($result);
42
    }
43
44
}