Passed
Push — master ( 4b152c...2ff9b2 )
by Iman
03:51
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 makeResult() 0 12 2
A send() 0 10 4
1
<?php
2
3
namespace crocodicstudio\crudbooster\controllers\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
        sendAndTerminate(response()->json($result));
0 ignored issues
show
Bug introduced by
The method json() does not exist on Symfony\Component\HttpFoundation\Response. It seems like you code against a sub-type of Symfony\Component\HttpFoundation\Response such as Illuminate\Http\Response or Illuminate\Http\JsonResponse or Illuminate\Http\RedirectResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        sendAndTerminate(response()->/** @scrutinizer ignore-call */ json($result));
Loading history...
42
    }
43
44
}