Passed
Push — task/laravel-breadcrumbs ( 3beccb...a96280 )
by Yonathan
10:46 queued 10s
created

TwoFactorCrudController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 32
c 0
b 0
f 0
dl 0
loc 58
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setupListOperation() 0 36 1
A setup() 0 8 2
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
7
class TwoFactorCrudController extends CrudController
8
{
9
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Http\C...perations\ListOperation requires some properties which are not provided by App\Http\Controllers\Admin\TwoFactorCrudController: $model, $query, $entity_name_plural
Loading history...
10
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Http\C...rations\UpdateOperation requires some properties which are not provided by App\Http\Controllers\Admin\TwoFactorCrudController: $model, $entity_name
Loading history...
11
12
    /**
13
     * Prepare the admin interface by setting the associated
14
     * model, setting the route, and adding custom columns/fields.
15
     *
16
     * @return void
17
     */
18
    public function setup() : void
19
    {
20
        $this->crud->setModel('App\Models\User');
21
        $this->crud->setRoute('admin/2fa');
22
        $this->crud->setEntityNameStrings('Manage 2FA', 'Manage 2FA');
23
        // Only show current user.
24
        if (\Auth::user()->hasRole('admin')) {
25
            $this->crud->addClause('where', 'id', '=', \Auth::user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
26
        }
27
    }
28
29
    public function setupListOperation()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function setupListOperation()
Loading history...
30
    {
31
        $this->crud->removeButton('update');
32
33
        $this->crud->addColumn([
34
            'name' => 'id',
35
            'type' => 'text',
36
            'label' => 'ID',
37
            'orderable' => false
38
        ]);
39
40
        $this->crud->addColumn([
41
            'name' => 'full_name',
42
            'type' => 'text',
43
            'label' => 'Name',
44
            'orderable' => false
45
        ]);
46
47
        $this->crud->addColumn([
48
            'name' => 'google2fa_secret',
49
            'type' => 'check',
50
            'label' => '2FA Enabled',
51
            'orderable' => false
52
        ]);
53
54
        $this->crud->addColumn([
55
            'name' => 'recovery_codes',
56
            'type' => 'array_count',
57
            'label' => 'Recovery Codes',
58
            'orderable' => false,
59
        ]);
60
61
        // Add the custom blade buttons (resources/views/vendor/backpack/crud/buttons).
62
        $this->crud->addButtonFromView('line', 'recovery_codes', 'recovery_codes', 'beginning');
63
        $this->crud->addButtonFromView('line', 'activate_2fa', 'activate_2fa', 'end');
64
        $this->crud->addButtonFromView('line', 'deactivate_2fa', 'deactivate_2fa', 'end');
65
    }
66
}
67