Conditions | 4 |
Paths | 2 |
Total Lines | 53 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
58 | public function displayGrid() |
||
59 | { |
||
60 | $this->grid = $this->add([ |
||
61 | 'CRUD', |
||
62 | 'itemCreate' => ActionBar::addButton('add'), |
||
63 | 'formCreate' => $this->getNodeForm(), |
||
64 | 'formUpdate' => $this->getNodeForm(), |
||
65 | 'fieldsCreate' => ['key', 'value'], |
||
66 | 'fieldsUpdate' => ['key', 'value'], |
||
67 | 'notifyDefault' => ['jsNotify', 'content' => __('Data is saved!'), 'color' => 'green'], |
||
68 | 'canUpdate' => false, //use custom update routine |
||
69 | 'canDelete' => false, //use custom delete routine |
||
70 | 'paginator' => false, |
||
71 | 'menu' => false, |
||
72 | ]); |
||
73 | |||
74 | $this->grid->table->addClass('selectable')->addStyle('cursor', 'pointer'); |
||
75 | |||
76 | $this->grid->setModel($model = $this->getModel()); |
||
77 | |||
78 | if ($model->action('count')->getOne() ) { |
||
79 | $this->grid->on('click', 'td', new jsExpression( |
||
80 | 'document.location=\'?parentId=\'+[]', |
||
81 | [(new jQuery())->closest('tr')->data('id')] |
||
1 ignored issue
–
show
|
|||
82 | )); |
||
83 | } |
||
84 | |||
85 | $this->grid->addDragHandler()->onReorder(function ($order) { |
||
1 ignored issue
–
show
|
|||
86 | $result = true; |
||
87 | foreach ($this->nodes()->get() as $node) { |
||
88 | $node->position = array_search($node->id, $order); |
||
89 | |||
90 | $result &= $node->save(); |
||
91 | } |
||
92 | |||
93 | $notifier = $result? $this->notify(__('Items reordered!')): $this->notifyError(__('Error saving order!')); |
||
94 | |||
95 | return $this->grid->jsSave($notifier); |
||
96 | }); |
||
97 | |||
98 | $this->addContolButton('update', $this->getUpdateModal(), 'edit'); |
||
99 | |||
100 | $this->addContolButton('delete', function ($jschain, $id) { |
||
101 | CommonData::find($id)->delete(); |
||
102 | |||
103 | return $jschain->closest('tr')->transition('fade left'); |
||
104 | }, 'red trash'); |
||
105 | |||
106 | $this->grid->addColumn('actions', ['Multiformat', function($row, $column) { |
||
107 | return [['Template', $this->getControlButtonsHtml($row)]]; |
||
108 | }, 'caption' => ' ']); |
||
109 | |||
110 | return $this; |
||
111 | } |
||
245 |