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:09
created

PermissionCrudController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Backpack\PermissionManager\app\Http\Controllers;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
7
// VALIDATION
8
9
class PermissionCrudController extends CrudController
10
{
11
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
12
    use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
13
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
14
    use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
15
16
    public function setup()
17
    {
18
        $role_model = config('backpack.permissionmanager.models.role');
0 ignored issues
show
Unused Code introduced by
$role_model is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
19
        $permission_model = config('backpack.permissionmanager.models.permission');
20
21
        $this->crud->setModel($permission_model);
22
        $this->crud->setEntityNameStrings(trans('backpack::permissionmanager.permission_singular'), trans('backpack::permissionmanager.permission_plural'));
23
        $this->crud->setRoute(backpack_url('permission'));
24
25
        // deny access according to configuration file
26
        if (config('backpack.permissionmanager.allow_permission_create') == false) {
27
            $this->crud->denyAccess('create');
28
        }
29
        if (config('backpack.permissionmanager.allow_permission_update') == false) {
30
            $this->crud->denyAccess('update');
31
        }
32
        if (config('backpack.permissionmanager.allow_permission_delete') == false) {
33
            $this->crud->denyAccess('delete');
34
        }
35
36
        $this->crud->operation('list', function () {
37
            $this->crud->addColumn([
38
                'name'  => 'name',
39
                'label' => trans('backpack::permissionmanager.name'),
40
                'type'  => 'text',
41
            ]);
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
        });
51
52
        $this->crud->operation(['create', 'update'], function () {
53
            $this->crud->addField([
54
                'name'  => 'name',
55
                'label' => trans('backpack::permissionmanager.name'),
56
                'type'  => 'text',
57
            ]);
58
59 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...
60
                $this->crud->addField([
61
                    'name'    => 'guard_name',
62
                    'label'   => trans('backpack::permissionmanager.guard_type'),
63
                    'type'    => 'select_from_array',
64
                    'options' => $this->getGuardTypes(),
65
                ]);
66
            }
67
68
            //otherwise, changes won't have effect
69
            \Cache::forget('spatie.permission.cache');
70
        });
71
    }
72
73
    /*
74
     * Get an array list of all available guard types
75
     * that have been defined in app/config/auth.php
76
     *
77
     * @return array
78
     **/
79 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...
80
    {
81
        $guards = config('auth.guards');
82
83
        $returnable = [];
84
        foreach ($guards as $key => $details) {
85
            $returnable[$key] = $key;
86
        }
87
88
        return $returnable;
89
    }
90
}
91