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
Push — master ( d1373b...643f9e )
by Cristian
07:33
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\RoleCrudRequest as StoreRequest;
8
use Backpack\PermissionManager\app\Http\Requests\RoleCrudRequest as UpdateRequest;
9
10
class RoleCrudController extends CrudController
11
{
12
    public function setup()
13
    {
14
        $role_model = config('backpack.permissionmanager.models.role');
15
        $permission_model = config('backpack.permissionmanager.models.permission');
16
17
        $this->crud->setModel($role_model);
18
        $this->crud->setEntityNameStrings(trans('backpack::permissionmanager.role'), trans('backpack::permissionmanager.roles'));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
19
        $this->crud->setRoute(backpack_url('role'));
20
21
        $this->crud->addColumn([
22
            'name'  => 'name',
23
            'label' => trans('backpack::permissionmanager.name'),
24
            'type'  => 'text',
25
        ]);
26
27 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...
28
            $this->crud->addColumn([
29
                'name'  => 'guard_name',
30
                'label' => trans('backpack::permissionmanager.guard_type'),
31
                'type'  => 'text',
32
            ]);
33
        }
34
35
        $this->crud->addColumn([
36
            // n-n relationship (with pivot table)
37
            'label'     => ucfirst(trans('backpack::permissionmanager.permission_plural')),
38
            'type'      => 'select_multiple',
39
            'name'      => 'permissions', // the method that defines the relationship in your Model
40
            'entity'    => 'permissions', // the method that defines the relationship in your Model
41
            'attribute' => 'name', // foreign key attribute that is shown to user
42
            'model'     => $permission_model, // foreign key model
43
            'pivot'     => true, // on create&update, do you need to add/delete pivot table entries?
44
        ]);
45
46
        $this->crud->addField([
47
            'name'  => 'name',
48
            'label' => trans('backpack::permissionmanager.name'),
49
            'type'  => 'text',
50
        ]);
51
52 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...
53
            $this->crud->addField([
54
                'name'    => 'guard_name',
55
                'label'   => trans('backpack::permissionmanager.guard_type'),
56
                'type'    => 'select_from_array',
57
                'options' => $this->getGuardTypes(),
58
            ]);
59
        }
60
61
        $this->crud->addField([
62
            'label'     => ucfirst(trans('backpack::permissionmanager.permission_plural')),
63
            'type'      => 'checklist',
64
            'name'      => 'permissions',
65
            'entity'    => 'permissions',
66
            'attribute' => 'name',
67
            'model'     => $permission_model,
68
            'pivot'     => true,
69
        ]);
70
71
        if (config('backpack.permissionmanager.allow_role_create') == false) {
72
            $this->crud->denyAccess('create');
73
        }
74
        if (config('backpack.permissionmanager.allow_role_update') == false) {
75
            $this->crud->denyAccess('update');
76
        }
77
        if (config('backpack.permissionmanager.allow_role_delete') == false) {
78
            $this->crud->denyAccess('delete');
79
        }
80
    }
81
82
    public function store(StoreRequest $request)
83
    {
84
        //otherwise, changes won't have effect
85
        \Cache::forget('spatie.permission.cache');
86
87
        return parent::storeCrud();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (storeCrud() instead of store()). Are you sure this is correct? If so, you might want to change this to $this->storeCrud().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
88
    }
89
90
    public function update(UpdateRequest $request)
91
    {
92
        //otherwise, changes won't have effect
93
        \Cache::forget('spatie.permission.cache');
94
95
        return parent::updateCrud();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (updateCrud() instead of update()). Are you sure this is correct? If so, you might want to change this to $this->updateCrud().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
96
    }
97
98
    /*
99
     * Get an array list of all available guard types
100
     * that have been defined in app/config/auth.php
101
     *
102
     * @return array
103
     **/
104 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...
105
    {
106
        $guards = config('auth.guards');
107
108
        $returnable = [];
109
        foreach ($guards as $key => $details) {
110
            $returnable[$key] = $key;
111
        }
112
113
        return $returnable;
114
    }
115
}
116