Passed
Push — master ( 41c09c...5f5681 )
by Iman
06:15
created

ApiKeysRepository   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A incrementHit() 0 3 1
A where() 0 3 1
A insertGetId() 0 7 1
A updateById() 0 3 1
A get() 0 3 1
A deleteById() 0 3 1
A table() 0 3 1
A getSecretKeys() 0 3 1
1
<?php
2
3
namespace crocodicstudio\crudbooster\Modules\ApiGeneratorModule;
4
5
use Illuminate\Support\Facades\DB;
6
7
class ApiKeysRepository
8
{
9
    public function incrementHit($serverSecret)
10
    {
11
        return $this->where(['secretkey' => $serverSecret])->increment('hit');
12
    }
13
14
    public function where($where)
15
    {
16
        return $this->table()->where($where);
17
    }
18
19
    private static function table()
20
    {
21
        return DB::table('cms_apikey');
22
    }
23
24
    public function getSecretKeys()
25
    {
26
        return $this->where(['status' => 'active'])->pluck('secretkey');
27
    }
28
29
    public function get()
30
    {
31
        return $this->table()->get();
32
    }
33
34
    public function deleteById($id)
35
    {
36
        return $this->where(['id' => $id])->delete();
37
    }
38
39
    public function updateById($status, $id)
40
    {
41
        return $this->where(['id' => $id])->update(['status' => $status]);
42
    }
43
44
    public function insertGetId($token)
45
    {
46
        return $this->table()->insertGetId([
47
            'secretkey' => $token,
48
            'created_at' => YmdHis(),
49
            'status' => 'active',
50
            'hit' => 0,
51
        ]);
52
    }
53
}