Completed
Push — master ( 1b6826...163bda )
by Tim
04:49 queued 02:26
created

ApiKeyController::makeKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 1
eloc 11
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\User;
6
use Illuminate\Http\Request;
7
use Chrisbjr\ApiGuard\Models\ApiKey;
8
use App\Http\Requests;
9
10
class ApiKeyController extends Controller
11
{
12
    protected $apiKey;
13
14
    /**
15
     * ApiKeyController constructor.
16
     * @param ApiKey $apiKey
17
     */
18
    public function __construct(ApiKey $apiKey)
19
    {
20
        $this->middleware('auth');
21
        $this->middleware('lang');
22
23
        $this->apiKey = $apiKey;
24
    }
25
26
    /**
27
     * Create a new api token.
28
     *
29
     * TODO: implement session to the view.
30
     * TODO: Build api key limit that the user can have max. 5 keys.
31
     * @param Request $request
32
     * @return \Illuminate\Http\RedirectResponse
33
     */
34
    public function makeKey(Request $request)
35
    {
36
        $id         = auth()->user()->id;
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
        $create     = $this->apiKey->make($id);
38
        $insertedId = $create->id;
39
40
        $serviceInsert          = $this->apiKey->find($insertedId);
41
        $serviceInsert->service = $request->get('service');
42
        $serviceInsert->save();
43
44
        $token = $this->apiKey->find($insertedId);
45
46
        session()->flash('message', 'Token created');
47
        session()->flash('token', $token->key);
48
        return redirect()->back(302);
49
    }
50
51
    public function revokeKey()
52
    {
53
54
    }
55
56
    /**
57
     * Get the apikey
58
     *
59
     * @param int $id the database id off the api key.
60
     * @return \Illuminate\Http\RedirectResponse
61
     */
62
    public function getKey($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    {
64
        return redirect()->back(302);
65
    }
66
67
    /**
68
     * Delete a api key out off the system.
69
     *
70
     * @param int $id the database id off the api key.
71
     * @return \Illuminate\Http\RedirectResponse
72
     */
73
    public function deleteKey($id)
74
    {
75
        $this->apiKey->destroy($id);
76
        session()->flash('message', 'The api key is deleted.');
77
78
        return redirect()->back(302);
79
    }
80
81
}
82