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
01:22
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
use Backpack\PermissionManager\app\Http\Requests\RoleStoreCrudRequest as StoreRequest;
8
use Backpack\PermissionManager\app\Http\Requests\RoleUpdateCrudRequest as UpdateRequest;
9
10
class RoleCrudController extends CrudController
11
{
12
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
13
    use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
14
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
15
    use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
16
17
    public function setup()
18
    {
19
        $role_model = config('backpack.permissionmanager.models.role');
20
        $permission_model = config('backpack.permissionmanager.models.permission');
21
22
        $this->crud->setModel($role_model);
23
        $this->crud->setEntityNameStrings(trans('backpack::permissionmanager.role'), trans('backpack::permissionmanager.roles'));
24
        $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...
25
26
        // deny access according to configuration file
27
        if (config('backpack.permissionmanager.allow_role_create') == false) {
28
            $this->crud->denyAccess('create');
29
        }
30
        if (config('backpack.permissionmanager.allow_role_update') == false) {
31
            $this->crud->denyAccess('update');
32
        }
33
        if (config('backpack.permissionmanager.allow_role_delete') == false) {
34
            $this->crud->denyAccess('delete');
35
        }
36
37
        $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...
38
            $this->crud->addColumn([
39
                'name'  => 'name',
40
                'label' => trans('backpack::permissionmanager.name'),
41
                'type'  => 'text',
42
            ]);
43 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...
44
                $this->crud->addColumn([
45
                    'name'  => 'guard_name',
46
                    'label' => trans('backpack::permissionmanager.guard_type'),
47
                    'type'  => 'text',
48
                ]);
49
            }
50
            $this->crud->addColumn([
51
                // n-n relationship (with pivot table)
52
                'label'     => ucfirst(trans('backpack::permissionmanager.permission_plural')),
53
                'type'      => 'select_multiple',
54
                'name'      => 'permissions', // the method that defines the relationship in your Model
55
                'entity'    => 'permissions', // the method that defines the relationship in your Model
56
                'attribute' => 'name', // foreign key attribute that is shown to user
57
                'model'     => $permission_model, // foreign key model
58
                'pivot'     => true, // on create&update, do you need to add/delete pivot table entries?
59
            ]);
60
        });
61
62
        $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...
63
            $this->crud->addField([
64
                'name'  => 'name',
65
                'label' => trans('backpack::permissionmanager.name'),
66
                'type'  => 'text',
67
            ]);
68
69 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...
70
                $this->crud->addField([
71
                    'name'    => 'guard_name',
72
                    'label'   => trans('backpack::permissionmanager.guard_type'),
73
                    'type'    => 'select_from_array',
74
                    'options' => $this->getGuardTypes(),
75
                ]);
76
            }
77
78
            $this->crud->addField([
79
                'label'     => ucfirst(trans('backpack::permissionmanager.permission_plural')),
80
                'type'      => 'checklist',
81
                'name'      => 'permissions',
82
                'entity'    => 'permissions',
83
                'attribute' => 'name',
84
                'model'     => $permission_model,
85
                'pivot'     => true,
86
            ]);
87
88
            //otherwise, changes won't have effect
89
            \Cache::forget('spatie.permission.cache');
90
        });
91
    }
92
93
    /*
94
     * Get an array list of all available guard types
95
     * that have been defined in app/config/auth.php
96
     *
97
     * @return array
98
     **/
99 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...
100
    {
101
        $guards = config('auth.guards');
102
103
        $returnable = [];
104
        foreach ($guards as $key => $details) {
105
            $returnable[$key] = $key;
106
        }
107
108
        return $returnable;
109
    }
110
}
111