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
02:32 queued 01:18
created

PermissionCrudController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 82
Duplicated Lines 31.71 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 6
dl 26
loc 82
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B setup() 15 56 6
A getGuardTypes() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Backpack\PermissionManager\app\Http\Controllers;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
// VALIDATION
7
8
class PermissionCrudController extends CrudController
9
{
10
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
11
    use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
12
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
13
    use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
14
15
    public function setup()
16
    {
17
        $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...
18
        $permission_model = config('backpack.permissionmanager.models.permission');
19
20
        $this->crud->setModel($permission_model);
21
        $this->crud->setEntityNameStrings(trans('backpack::permissionmanager.permission_singular'), trans('backpack::permissionmanager.permission_plural'));
22
        $this->crud->setRoute(backpack_url('permission'));
0 ignored issues
show
Bug introduced by
It seems like backpack_url('permission') 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...
23
24
        // deny access according to configuration file
25
        if (config('backpack.permissionmanager.allow_permission_create') == false) {
26
            $this->crud->denyAccess('create');
27
        }
28
        if (config('backpack.permissionmanager.allow_permission_update') == false) {
29
            $this->crud->denyAccess('update');
30
        }
31
        if (config('backpack.permissionmanager.allow_permission_delete') == false) {
32
            $this->crud->denyAccess('delete');
33
        }
34
35
        $this->crud->operation('list', function () {
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...
36
            $this->crud->addColumn([
37
                'name'  => 'name',
38
                'label' => trans('backpack::permissionmanager.name'),
39
                'type'  => 'text',
40
            ]);
41
42 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...
43
                $this->crud->addColumn([
44
                    'name'  => 'guard_name',
45
                    'label' => trans('backpack::permissionmanager.guard_type'),
46
                    'type'  => 'text',
47
                ]);
48
            }
49
        });
50
51
        $this->crud->operation(['create', 'update'], function () {
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...
52
            $this->crud->addField([
53
                'name'  => 'name',
54
                'label' => trans('backpack::permissionmanager.name'),
55
                'type'  => 'text',
56
            ]);
57
58 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...
59
                $this->crud->addField([
60
                    'name'    => 'guard_name',
61
                    'label'   => trans('backpack::permissionmanager.guard_type'),
62
                    'type'    => 'select_from_array',
63
                    'options' => $this->getGuardTypes(),
64
                ]);
65
            }
66
67
            //otherwise, changes won't have effect
68
            \Cache::forget('spatie.permission.cache');
69
        });
70
    }
71
72
    /*
73
     * Get an array list of all available guard types
74
     * that have been defined in app/config/auth.php
75
     *
76
     * @return array
77
     **/
78 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...
79
    {
80
        $guards = config('auth.guards');
81
82
        $returnable = [];
83
        foreach ($guards as $key => $details) {
84
            $returnable[$key] = $key;
85
        }
86
87
        return $returnable;
88
    }
89
}
90