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 ( 13db61...ee958b )
by Cristian
01:31
created

PermissionCrudController::addFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 9.7
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
use Backpack\PermissionManager\app\Http\Requests\PermissionStoreCrudRequest as StoreRequest;
7
use Backpack\PermissionManager\app\Http\Requests\PermissionUpdateCrudRequest as UpdateRequest;
8
9
// VALIDATION
10
11
class PermissionCrudController extends CrudController
12
{
13
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
14
    use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
15
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
16
    use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
17
18 View Code Duplication
    public function setup()
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...
19
    {
20
        $this->role_model = $role_model = config('backpack.permissionmanager.models.role');
0 ignored issues
show
Bug introduced by
The property role_model does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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...
21
        $this->permission_model = $permission_model = config('backpack.permissionmanager.models.permission');
0 ignored issues
show
Bug introduced by
The property permission_model does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
23
        $this->crud->setModel($permission_model);
24
        $this->crud->setEntityNameStrings(trans('backpack::permissionmanager.permission_singular'), trans('backpack::permissionmanager.permission_plural'));
25
        $this->crud->setRoute(backpack_url('permission'));
26
27
        // deny access according to configuration file
28
        if (config('backpack.permissionmanager.allow_permission_create') == false) {
29
            $this->crud->denyAccess('create');
30
        }
31
        if (config('backpack.permissionmanager.allow_permission_update') == false) {
32
            $this->crud->denyAccess('update');
33
        }
34
        if (config('backpack.permissionmanager.allow_permission_delete') == false) {
35
            $this->crud->denyAccess('delete');
36
        }
37
    }
38
39 View Code Duplication
    public function setupListOperation()
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...
40
    {
41
        $this->crud->addColumn([
42
            'name'  => 'name',
43
            'label' => trans('backpack::permissionmanager.name'),
44
            'type'  => 'text',
45
        ]);
46
47
        if (config('backpack.permissionmanager.multiple_guards')) {
48
            $this->crud->addColumn([
49
                'name'  => 'guard_name',
50
                'label' => trans('backpack::permissionmanager.guard_type'),
51
                'type'  => 'text',
52
            ]);
53
        }
54
    }
55
56
    public function setupCreateOperation()
57
    {
58
        $this->addFields();
59
        $this->crud->setValidation(StoreRequest::class);
60
61
        //otherwise, changes won't have effect
62
        \Cache::forget('spatie.permission.cache');
63
    }
64
65
    public function setupUpdateOperation()
66
    {
67
        $this->addFields();
68
        $this->crud->setValidation(UpdateRequest::class);
69
        
70
        //otherwise, changes won't have effect
71
        \Cache::forget('spatie.permission.cache');
72
    }
73
74 View Code Duplication
    private function addFields()
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...
75
    {
76
        $this->crud->addField([
77
            'name'  => 'name',
78
            'label' => trans('backpack::permissionmanager.name'),
79
            'type'  => 'text',
80
        ]);
81
82
        if (config('backpack.permissionmanager.multiple_guards')) {
83
            $this->crud->addField([
84
                'name'    => 'guard_name',
85
                'label'   => trans('backpack::permissionmanager.guard_type'),
86
                'type'    => 'select_from_array',
87
                'options' => $this->getGuardTypes(),
88
            ]);
89
        }
90
    }
91
92
    /*
93
     * Get an array list of all available guard types
94
     * that have been defined in app/config/auth.php
95
     *
96
     * @return array
97
     **/
98 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...
99
    {
100
        $guards = config('auth.guards');
101
102
        $returnable = [];
103
        foreach ($guards as $key => $details) {
104
            $returnable[$key] = $key;
105
        }
106
107
        return $returnable;
108
    }
109
}
110