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 ( 5ea250...759401 )
by Cristian
01:31
created

UserCrudController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Backpack\PermissionManager\app\Http\Controllers;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
use Backpack\CRUD\app\Http\Requests\CrudRequest;
7
use Backpack\PermissionManager\app\Http\Requests\UserStoreCrudRequest as StoreRequest;
8
use Backpack\PermissionManager\app\Http\Requests\UserUpdateCrudRequest as UpdateRequest;
9
10
class UserCrudController extends CrudController
11
{
12
    public function setup()
13
    {
14
        /*
15
        |--------------------------------------------------------------------------
16
        | BASIC CRUD INFORMATION
17
        |--------------------------------------------------------------------------
18
        */
19
        $this->crud->setModel(config('backpack.permissionmanager.user_model'));
20
        $this->crud->setEntityNameStrings(trans('backpack::permissionmanager.user'), trans('backpack::permissionmanager.users'));
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...
21
        $this->crud->setRoute(config('backpack.base.route_prefix').'/user');
22
        $this->crud->enableAjaxTable();
23
24
        // Columns.
25
        $this->crud->setColumns([
26
            [
27
                'name'  => 'name',
28
                'label' => trans('backpack::permissionmanager.name'),
29
                'type'  => 'text',
30
            ],
31
            [
32
                'name'  => 'email',
33
                'label' => trans('backpack::permissionmanager.email'),
34
                'type'  => 'email',
35
            ],
36
            [ // n-n relationship (with pivot table)
37
               'label'     => trans('backpack::permissionmanager.roles'), // Table column heading
38
               'type'      => 'select_multiple',
39
               'name'      => 'roles', // the method that defines the relationship in your Model
40
               'entity'    => 'roles', // the method that defines the relationship in your Model
41
               'attribute' => 'name', // foreign key attribute that is shown to user
42
               'model'     => config('laravel-permission.models.role'), // foreign key model
43
            ],
44
            [ // n-n relationship (with pivot table)
45
               'label'     => trans('backpack::permissionmanager.extra_permissions'), // Table column heading
46
               'type'      => 'select_multiple',
47
               'name'      => 'permissions', // the method that defines the relationship in your Model
48
               'entity'    => 'permissions', // the method that defines the relationship in your Model
49
               'attribute' => 'name', // foreign key attribute that is shown to user
50
               'model'     => config('laravel-permission.models.permission'), // foreign key model
51
            ],
52
        ]);
53
54
        // Fields
55
        $this->crud->addFields([
56
            [
57
                'name'  => 'name',
58
                'label' => trans('backpack::permissionmanager.name'),
59
                'type'  => 'text',
60
            ],
61
            [
62
                'name'  => 'email',
63
                'label' => trans('backpack::permissionmanager.email'),
64
                'type'  => 'email',
65
            ],
66
            [
67
                'name'  => 'password',
68
                'label' => trans('backpack::permissionmanager.password'),
69
                'type'  => 'password',
70
            ],
71
            [
72
                'name'  => 'password_confirmation',
73
                'label' => trans('backpack::permissionmanager.password_confirmation'),
74
                'type'  => 'password',
75
            ],
76
            [
77
            // two interconnected entities
78
            'label'             => trans('backpack::permissionmanager.user_role_permission'),
79
            'field_unique_name' => 'user_role_permission',
80
            'type'              => 'checklist_dependency',
81
            'name'              => 'roles_and_permissions', // the methods that defines the relationship in your Model
82
            'subfields'         => [
83
                    'primary' => [
84
                        'label'            => trans('backpack::permissionmanager.roles'),
85
                        'name'             => 'roles', // the method that defines the relationship in your Model
86
                        'entity'           => 'roles', // the method that defines the relationship in your Model
87
                        'entity_secondary' => 'permissions', // the method that defines the relationship in your Model
88
                        'attribute'        => 'name', // foreign key attribute that is shown to user
89
                        'model'            => config('laravel-permission.models.role'), // foreign key model
90
                        'pivot'            => true, // on create&update, do you need to add/delete pivot table entries?]
91
                        'number_columns'   => 3, //can be 1,2,3,4,6
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
92
                    ],
93
                    'secondary' => [
94
                        'label'          => ucfirst(trans('backpack::permissionmanager.permission_singular')),
95
                        'name'           => 'permissions', // the method that defines the relationship in your Model
96
                        'entity'         => 'permissions', // the method that defines the relationship in your Model
97
                        'entity_primary' => 'roles', // the method that defines the relationship in your Model
98
                        'attribute'      => 'name', // foreign key attribute that is shown to user
99
                        'model'          => "Backpack\PermissionManager\app\Models\Permission", // foreign key model
100
                        'pivot'          => true, // on create&update, do you need to add/delete pivot table entries?]
101
                        'number_columns' => 3, //can be 1,2,3,4,6
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
102
                    ],
103
                ],
104
            ],
105
        ]);
106
    }
107
108
    /**
109
     * Store a newly created resource in the database.
110
     *
111
     * @param StoreRequest $request - type injection used for validation using Requests
112
     *
113
     * @return \Illuminate\Http\RedirectResponse
114
     */
115
    public function store(StoreRequest $request)
116
    {
117
        $this->handlePasswordInput($request);
118
119
        return parent::storeCrud($request);
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...
120
    }
121
122
    /**
123
     * Update the specified resource in the database.
124
     *
125
     * @param UpdateRequest $request - type injection used for validation using Requests
126
     *
127
     * @return \Illuminate\Http\RedirectResponse
128
     */
129
    public function update(UpdateRequest $request)
130
    {
131
        $this->handlePasswordInput($request);
132
133
        return parent::updateCrud($request);
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...
134
    }
135
136
    /**
137
     * Handle password input fields.
138
     *
139
     * @param CrudRequest $request
140
     */
141
    protected function handlePasswordInput(CrudRequest $request)
142
    {
143
        // Remove fields not present on the user.
144
        $request->request->remove('password_confirmation');
145
146
        // Encrypt password if specified.
147
        if ($request->input('password')) {
148
            $request->request->set('password', bcrypt($request->input('password')));
0 ignored issues
show
Bug introduced by
It seems like $request->input('password') targeting Illuminate\Http\Concerns...ractsWithInput::input() can also be of type array; however, bcrypt() 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...
149
        } else {
150
            $request->request->remove('password');
151
        }
152
    }
153
}
154