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 (#172)
by
unknown
01:28
created

PermissionCrudController::setup()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 69
rs 8.6763
c 0
b 0
f 0
cc 4
nc 8
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 PermissionCrudController extends CrudController
11
{
12
    public function setup()
13
    {
14
        $role_model = config('permission.models.role');
15
        $permission_model = config('permission.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(config('backpack.base.route_prefix').'/role');
20
21
        $this->crud->setColumns([
22
            [
23
                'name'  => 'name',
24
                'label' => trans('backpack::permissionmanager.name'),
25
                'type'  => 'text',
26
            ],
27
            [
28
                'name'  => 'guard_name',
29
                'label' => trans('backpack::permissionmanager.guard_type'),
30
                'type'  => 'text',
31
            ],
32
            [
33
                'name'  => 'guard_name',
34
                'label' => trans('backpack::permissionmanager.guard_type'),
35
                'type'  => 'text',
36
            ],
37
            [
38
                // n-n relationship (with pivot table)
39
                'label'     => ucfirst(trans('backpack::permissionmanager.permission_plural')),
40
                'type'      => 'select_multiple',
41
                'name'      => 'permissions', // the method that defines the relationship in your Model
42
                'entity'    => 'permissions', // the method that defines the relationship in your Model
43
                'attribute' => 'name', // foreign key attribute that is shown to user
44
                'model'     => $permission_model, // foreign key model
45
                'pivot'     => true, // on create&update, do you need to add/delete pivot table entries?
46
            ],
47
        ]);
48
49
        $this->crud->addField([
50
            'name'  => 'name',
51
            'label' => trans('backpack::permissionmanager.name'),
52
            'type'  => 'text',
53
        ]);
54
55
        $this->crud->addField([
56
            'name'    => 'guard_name',
57
            'label'   => trans('backpack::permissionmanager.guard_type'),
58
            'type'    => 'select_from_array',
59
            'options' => $this->getGuardTypes(),
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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
    private function getGuardTypes()
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