| Conditions | 10 |
| Paths | 35 |
| Total Lines | 41 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 13 | public function getParamForm($typename, $linkId = 0) |
||
| 14 | { |
||
| 15 | $data = [ |
||
| 16 | 'title' => '', |
||
| 17 | 'link' => '', |
||
| 18 | 'button_id' => 0, |
||
| 19 | 'buttons' => [], |
||
| 20 | ]; |
||
| 21 | |||
| 22 | if ($linkId) { |
||
| 23 | $link = Link::find($linkId); |
||
| 24 | $data['title'] = $link->title; |
||
| 25 | $data['link'] = $link->link; |
||
| 26 | if (Route::currentRouteName() != 'showButtons') { |
||
| 27 | $data['button_id'] = $link->button_id; |
||
| 28 | } |
||
| 29 | |||
| 30 | if (!empty($link->type_params) && is_string($link->type_params)) { |
||
| 31 | $typeParams = json_decode($link->type_params, true); |
||
| 32 | if (is_array($typeParams)) { |
||
| 33 | $data = array_merge($data, $typeParams); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 | if ($typename === 'predefined') { |
||
| 38 | $buttons = Button::select()->orderBy('name', 'asc')->get(); |
||
| 39 | foreach ($buttons as $btn) { |
||
| 40 | $data['buttons'][] = [ |
||
| 41 | 'name' => $btn->name, |
||
| 42 | 'title' => $btn->alt, |
||
| 43 | 'exclude' => $btn->exclude, |
||
| 44 | 'selected' => ($linkId && isset($link) && $link->button_id == $btn->id), |
||
| 45 | ]; |
||
| 46 | } |
||
| 47 | return view('components.pageitems.predefined-form', $data); |
||
| 48 | } |
||
| 49 | |||
| 50 | // Set the block asset context before returning the view |
||
| 51 | setBlockAssetContext($typename); |
||
| 52 | |||
| 53 | return view($typename . '.form', $data); |
||
| 54 | } |
||
| 102 | } |