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 (#60)
by Agus
01:07
created

MenuItemCrudController::setup()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 8.8945
c 0
b 0
f 0
cc 2
nc 2
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Backpack\MenuCRUD\app\Http\Controllers\Admin;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
7
class MenuItemCrudController extends CrudController
8
{
9
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
10
    use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
11
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
12
    use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
13
    use \Backpack\CRUD\app\Http\Controllers\Operations\ReorderOperation;
14
15
    private $menu_id;
16
    private $menu;
17
18
    public function setup()
19
    {
20
        $this->menu_id = \Route::current()->parameter('menu_id');
21
        $this->menu = \Backpack\MenuCRUD\app\Models\Menu::find($this->menu_id);
22
        if ($this->menu == null) {
23
            abort(404);
24
        }
25
26
        $this->crud->setModel("Backpack\MenuCRUD\app\Models\MenuItem");
27
        $this->crud->setRoute(config('backpack.base.route_prefix').'/menu-item');
28
        $this->crud->setEntityNameStrings('menu item', 'menu items');
29
        $this->crud->addClause('orderBy', 'lft', 'asc');
30
        $this->crud->addClause('where', 'menu_id', $this->menu_id);
31
32
        $this->crud->setHeading('menu items'." - <a href='".backpack_url('menu/'.$this->menu_id.'/show')."'>".$this->menu->name.'</a>', false);
33
34
        $this->crud->enableReorder('name', 30); // Basically infinite
35
36
        $this->crud->operation('list', function () {
37
            $this->crud->addColumn([
38
                'name' => 'name',
39
                'label' => 'Label',
40
            ]);
41
            $this->crud->addColumn([
42
                'label' => 'Parent',
43
                'type' => 'select',
44
                'name' => 'parent_id',
45
                'entity' => 'parent',
46
                'attribute' => 'name',
47
                'model' => "\Backpack\MenuCRUD\app\Models\MenuItem",
48
            ]);
49
        });
50
51
        $this->crud->operation(['create', 'update'], function () {
52
            $this->crud->addField([
53
                'name' => 'name',
54
                'label' => 'Label',
55
            ]);
56
            $this->crud->addField([
57
                'name'  => 'menu_id',
58
                'type'  => 'hidden',
59
                'value' => $this->menu_id,
60
            ]);
61
            $this->crud->addField([
62
                'label' => 'Parent',
63
                'type' => 'select',
64
                'name' => 'parent_id',
65
                'entity' => 'parent',
66
                'attribute' => 'name',
67
                'model' => "\Backpack\MenuCRUD\app\Models\MenuItem",
68
            ]);
69
            $this->crud->addField([
70
                'name' => ['type', 'link', 'page_id'],
71
                'label' => 'Type',
72
                'type' => 'page_or_link',
73
                'page_model' => '\Backpack\PageManager\app\Models\Page',
74
            ]);
75
        });
76
    }
77
}
78