We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 2 |
| Paths | 2 |
| Total Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 |