Completed
Push — 2.0 ( 090eab...b837a7 )
by Nicolas
14:41
created

ApiKeysController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 46
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A index() 0 8 1
A create() 0 8 1
A destroy() 0 8 1
1
<?php namespace Modules\User\Http\Controllers\Admin\Account;
2
3
use Modules\Core\Contracts\Authentication;
4
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
5
use Modules\User\Entities\UserToken;
6
use Modules\User\Repositories\UserTokenRepository;
7
8
class ApiKeysController extends AdminBaseController
9
{
10
    /**
11
     * @var Authentication
12
     */
13
    private $auth;
14
    /**
15
     * @var UserTokenRepository
16
     */
17
    private $userToken;
18
19
    public function __construct(Authentication $auth, UserTokenRepository $userToken)
20
    {
21
        parent::__construct();
22
23
        $this->auth = $auth;
24
        $this->userToken = $userToken;
25
    }
26
27
    public function index()
28
    {
29
        $tokens = $this->userToken->allForUser($this->auth->id());
30
31
        $this->assetPipeline->requireJs('clipboard.js');
32
33
        return view('user::admin.account.api-keys.index', compact('tokens'));
34
    }
35
36
    public function create()
37
    {
38
        $this->userToken->generateFor($this->auth->id());
39
40
        flash(trans('user:users.token generated'));
0 ignored issues
show
Bug introduced by
It seems like trans('user:users.token generated') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, flash() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
41
42
        return redirect()->route('admin.account.api.index');
43
    }
44
45
    public function destroy(UserToken $userToken)
46
    {
47
        $this->userToken->destroy($userToken);
48
49
        flash(trans('core::core.messages.resource deleted', ['name' => 'Api Token']));
0 ignored issues
show
Bug introduced by
It seems like trans('core::core.messag...'name' => 'Api Token')) targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, flash() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
50
51
        return redirect()->route('admin.account.api.index');
52
    }
53
}
54