Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#199)
by Cristian
02:32 queued 01:18
created

RoleCrudController::getGuardTypes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Backpack\PermissionManager\app\Http\Controllers;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
// VALIDATION
7
8
class RoleCrudController extends CrudController
9
{
10
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
11
    use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
12
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
13
    use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
14
15
    public function setup()
16
    {
17
        $role_model = config('backpack.permissionmanager.models.role');
18
        $permission_model = config('backpack.permissionmanager.models.permission');
19
20
        $this->crud->setModel($role_model);
21
        $this->crud->setEntityNameStrings(trans('backpack::permissionmanager.role'), trans('backpack::permissionmanager.roles'));
22
        $this->crud->setRoute(backpack_url('role'));
0 ignored issues
show
Bug introduced by
It seems like backpack_url('role') targeting backpack_url() can also be of type object<Illuminate\Contracts\Routing\UrlGenerator>; however, Backpack\CRUD\CrudPanel::setRoute() does only seem to accept string, 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...
23
24
        // deny access according to configuration file
25
        if (config('backpack.permissionmanager.allow_role_create') == false) {
26
            $this->crud->denyAccess('create');
27
        }
28
        if (config('backpack.permissionmanager.allow_role_update') == false) {
29
            $this->crud->denyAccess('update');
30
        }
31
        if (config('backpack.permissionmanager.allow_role_delete') == false) {
32
            $this->crud->denyAccess('delete');
33
        }
34
35
        $this->crud->operation('list', function () use ($permission_model) {
0 ignored issues
show
Bug introduced by
The method operation() does not exist on Backpack\CRUD\CrudPanel. Did you maybe mean doingListOperation()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
36
            $this->crud->addColumn([
37
                'name'  => 'name',
38
                'label' => trans('backpack::permissionmanager.name'),
39
                'type'  => 'text',
40
            ]);
41 View Code Duplication
            if (config('backpack.permissionmanager.multiple_guards')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
                $this->crud->addColumn([
43
                    'name'  => 'guard_name',
44
                    'label' => trans('backpack::permissionmanager.guard_type'),
45
                    'type'  => 'text',
46
                ]);
47
            }
48
            $this->crud->addColumn([
49
                // n-n relationship (with pivot table)
50
                'label'     => ucfirst(trans('backpack::permissionmanager.permission_plural')),
51
                'type'      => 'select_multiple',
52
                'name'      => 'permissions', // the method that defines the relationship in your Model
53
                'entity'    => 'permissions', // the method that defines the relationship in your Model
54
                'attribute' => 'name', // foreign key attribute that is shown to user
55
                'model'     => $permission_model, // foreign key model
56
                'pivot'     => true, // on create&update, do you need to add/delete pivot table entries?
57
            ]);
58
        });
59
60
        $this->crud->operation(['create', 'update'], function () use ($permission_model) {
0 ignored issues
show
Bug introduced by
The method operation() does not exist on Backpack\CRUD\CrudPanel. Did you maybe mean doingListOperation()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
61
            $this->crud->addField([
62
                'name'  => 'name',
63
                'label' => trans('backpack::permissionmanager.name'),
64
                'type'  => 'text',
65
            ]);
66
67 View Code Duplication
            if (config('backpack.permissionmanager.multiple_guards')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
                $this->crud->addField([
69
                    'name'    => 'guard_name',
70
                    'label'   => trans('backpack::permissionmanager.guard_type'),
71
                    'type'    => 'select_from_array',
72
                    'options' => $this->getGuardTypes(),
73
                ]);
74
            }
75
76
            $this->crud->addField([
77
                'label'     => ucfirst(trans('backpack::permissionmanager.permission_plural')),
78
                'type'      => 'checklist',
79
                'name'      => 'permissions',
80
                'entity'    => 'permissions',
81
                'attribute' => 'name',
82
                'model'     => $permission_model,
83
                'pivot'     => true,
84
            ]);
85
86
            //otherwise, changes won't have effect
87
            \Cache::forget('spatie.permission.cache');
88
        });
89
    }
90
91
    /*
92
     * Get an array list of all available guard types
93
     * that have been defined in app/config/auth.php
94
     *
95
     * @return array
96
     **/
97 View Code Duplication
    private function getGuardTypes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99
        $guards = config('auth.guards');
100
101
        $returnable = [];
102
        foreach ($guards as $key => $details) {
103
            $returnable[$key] = $key;
104
        }
105
106
        return $returnable;
107
    }
108
}
109