Passed
Push — master ( 4147d7...c7bef9 )
by Iman
06:57
created

AdminApiKeyController::cbInit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace crocodicstudio\crudbooster\Modules\ApiGeneratorModule;
4
5
use crocodicstudio\crudbooster\controllers\CBController;
6
use crocodicstudio\crudbooster\helpers\CbValidator;
7
use Illuminate\Support\Facades\Request;
8
use Illuminate\Support\Facades\DB;
9
use Illuminate\Support\Facades\Route;
10
11
class AdminApiKeyController extends CBController
12
{
13
    public function cbInit()
14
    {
15
        $this->table = 'cms_apicustom';
16
        $this->primaryKey = "id";
17
        $this->title_field = "nama";
18
        $this->button_show = false;
0 ignored issues
show
Bug Best Practice introduced by
The property button_show does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19
        $this->button_new = false;
0 ignored issues
show
Bug Best Practice introduced by
The property button_new does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20
        $this->deleteBtn = false;
21
        $this->button_add = false;
0 ignored issues
show
Bug Best Practice introduced by
The property button_add does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
        $this->button_import = false;
23
        $this->buttonExport = false;
24
    }
25
26
    public function getSecretKey()
27
    {
28
        $this->cbLoader();
29
        $data['page_title'] = 'API Generator';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
30
        $data['apikeys'] = DB::table('cms_apikey')->get();
31
32
        return view('CbApiGen::api_key', $data);
33
    }
34
35
    function getGenerateScreetKey()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
36
    {
37
        $this->cbLoader();
38
        //Generate a random string.
39
        $token = openssl_random_pseudo_bytes(16);
40
41
        //Convert the binary data into hexadecimal representation.
42
        $token = bin2hex($token);
43
44
        $id = DB::table('cms_apikey')->insertGetId([
45
                'screetkey' => $token,
46
                'created_at' => date('Y-m-d H:i:s'),
47
                'status' => 'active',
48
                'hit' => 0,
49
            ]);
50
51
        $response = [];
52
        $response['key'] = $token;
53
        $response['id'] = $id;
54
55
        return response()->json($response);
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

55
        return response()->/** @scrutinizer ignore-call */ json($response);
Loading history...
56
    }
57
58
    public function getStatusApikey()
59
    {
60
        CbValidator::valid(['id' => 'required', 'status' => 'required'], 'view');
61
62
        $id = request('id');
63
        $status = (request('status') == 1) ? "active" : "non active";
64
65
        DB::table('cms_apikey')->where('id', $id)->update(['status' => $status]);
66
67
        backWithMsg('You have been update api key status !');
68
    }
69
70
    public function getDeleteApiKey()
71
    {
72
        $id = request('id');
73
        if (DB::table('cms_apikey')->where('id', $id)->delete()) {
74
            return response()->json(['status' => 1]);
75
        }
76
77
        return response()->json(['status' => 0]);
78
    }
79
80
}
81