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

PermissionCrudController::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\PermissionCrudRequest as StoreRequest;
8
use Backpack\PermissionManager\app\Http\Requests\PermissionCrudRequest as UpdateRequest;
9
10
class PermissionCrudController extends CrudController
11
{
12
    public function setup()
13
    {
14
        $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...
15
        $permission_model = config('backpack.permissionmanager.models.permission');
16
17
        $this->crud->setModel($permission_model);
18
        $this->crud->setEntityNameStrings(trans('backpack::permissionmanager.permission_singular'), trans('backpack::permissionmanager.permission_plural'));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 156 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('permission'));
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->addField([
36
            'name'  => 'name',
37
            'label' => trans('backpack::permissionmanager.name'),
38
            'type'  => 'text',
39
        ]);
40
41 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...
42
            $this->crud->addField([
43
                'name'    => 'guard_name',
44
                'label'   => trans('backpack::permissionmanager.guard_type'),
45
                'type'    => 'select_from_array',
46
                'options' => $this->getGuardTypes(),
47
            ]);
48
        }
49
50
        if (config('backpack.permissionmanager.allow_permission_create') == false) {
51
            $this->crud->denyAccess('create');
52
        }
53
        if (config('backpack.permissionmanager.allow_permission_update') == false) {
54
            $this->crud->denyAccess('update');
55
        }
56
        if (config('backpack.permissionmanager.allow_permission_delete') == false) {
57
            $this->crud->denyAccess('delete');
58
        }
59
    }
60
61
    public function store(StoreRequest $request)
62
    {
63
        //otherwise, changes won't have effect
64
        \Cache::forget('spatie.permission.cache');
65
66
        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...
67
    }
68
69
    public function update(UpdateRequest $request)
70
    {
71
        //otherwise, changes won't have effect
72
        \Cache::forget('spatie.permission.cache');
73
74
        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...
75
    }
76
77
    /*
78
     * Get an array list of all available guard types
79
     * that have been defined in app/config/auth.php
80
     *
81
     * @return array
82
     **/
83 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...
84
    {
85
        $guards = config('auth.guards');
86
87
        $returnable = [];
88
        foreach ($guards as $key => $details) {
89
            $returnable[$key] = $key;
90
        }
91
92
        return $returnable;
93
    }
94
}
95