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 ( e3a208...f2d716 )
by Cristian
02:33
created

SettingCrudController::edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 15
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
namespace Backpack\Settings\app\Http\Controllers;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
// VALIDATION
7
use Backpack\Settings\app\Http\Requests\SettingRequest as StoreRequest;
8
use Backpack\Settings\app\Http\Requests\SettingRequest as UpdateRequest;
9
10
class SettingCrudController extends CrudController
11
{
12
    public function __construct()
13
    {
14
        parent::__construct();
15
16
        $this->crud->setModel("Backpack\Settings\app\Models\Setting");
17
        $this->crud->setEntityNameStrings('setting', 'settings');
18
        $this->crud->setRoute('admin/setting');
19
        $this->crud->denyAccess(['create', 'delete']);
20
        $this->crud->setColumns(['name', 'value', 'description']);
21
        $this->crud->addField([
22
                                'name'     => 'name',
23
                                'label'    => 'Name',
24
                                'type'     => 'text',
25
                                'disabled' => 'disabled',
26
                            ]);
27
    }
28
29
    /**
30
     * Display all rows in the database for this entity.
31
     * This overwrites the default CrudController behaviour:
32
     * - instead of showing all entries, only show the "active" ones.
33
     *
34
     * @return Response
35
     */
36
    public function index()
37
    {
38
        // if view_table_permission is false, abort
39
        $this->crud->hasAccessOrFail('list');
40
        $this->crud->addClause('where', 'active', 1); // <---- this is where it's different from CrudController::index()
41
42
        $this->data['entries'] = $this->crud->getEntries();
43
        $this->data['crud'] = $this->crud;
44
        $this->data['title'] = ucfirst($this->crud->entity_name_plural);
45
46
        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
47
        return view('crud::list', $this->data);
48
    }
49
50
    public function store(StoreRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    {
52
        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...
53
    }
54
55
56
    /**
57
     * Show the form for editing the specified resource.
58
     *
59
     * @param int $id
60
     *
61
     * @return Response
62
     */
63
    public function edit($id)
64
    {
65
        $this->crud->hasAccessOrFail('update');
66
67
        $this->data['entry'] = $this->crud->getEntry($id);
68
        $this->crud->addField((array)json_decode($this->data['entry']->field)); // <---- this is where it's different
69
        $this->data['crud'] = $this->crud;
70
        $this->data['fields'] = $this->crud->getUpdateFields($id);
71
        $this->data['title'] = trans('backpack::crud.edit').' '.$this->crud->entity_name;
72
73
        $this->data['id'] = $id;
74
75
        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
76
        return view('crud::edit', $this->data);
77
    }
78
79
80
    public function update(UpdateRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
    {
82
        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...
83
    }
84
}
85