| Conditions | 4 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 24 |
| 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 |
||
| 38 | public function boot() |
||
| 39 | { |
||
| 40 | //Labels |
||
| 41 | Form::macro('nLabel', function ($name, $value, $required = false, $options = []) { |
||
| 42 | if ($required) { |
||
| 43 | $value .= '<span style="color: #dc3545; font-weight:700">*</span>'; |
||
| 44 | } |
||
| 45 | |||
| 46 | return Form::label($name, $value, $options, false); |
||
| 47 | }); |
||
| 48 | |||
| 49 | Form::macro('hLabel', function ($name, $value, $required = false, $col_size = 2, $options = []) { |
||
| 50 | if ($required) { |
||
| 51 | $value .= '<span style="color: #dc3545; font-weight:700">*</span>'; |
||
| 52 | } |
||
| 53 | |||
| 54 | return Form::label($name, $value, array_merge(['class' => "col-md-$col_size col-form-label"], $options), false); |
||
| 55 | }); |
||
| 56 | |||
| 57 | Form::macro('fLabel', function ($name, $value, $required = false, $options = []) { |
||
| 58 | if ($required) { |
||
| 59 | $value .= '<span style="color: #dc3545; font-weight:700">*</span>'; |
||
| 60 | } |
||
| 61 | |||
| 62 | return str_replace('label', 'span', Form::label($name, $value, $options, false)); |
||
| 63 | }); |
||
| 64 | |||
| 65 | //Errors |
||
| 66 | Form::macro('nError', function ($name, $msg = null) { |
||
| 67 | return '<span id="'.$name.'-error" class="invalid-feedback">'.$msg.'</span>'; |
||
| 68 | }); |
||
| 69 | |||
| 70 | Form::macro('hError', function ($name, $msg = null) { |
||
| 71 | return '<span id="'.$name.'-error" class="invalid-feedback">'.$msg.'</span>'; |
||
| 72 | }); |
||
| 73 | |||
| 74 | Form::macro('fError', function ($name, $msg = null) { |
||
| 75 | return '<span id="'.$name.'-error" class="invalid-feedback">'.$msg.'</span>'; |
||
| 76 | }); |
||
| 77 | |||
| 78 | //Actions |
||
| 79 | Form::macro('nSubmit', function ($name, $value, $options = []) { |
||
| 80 | $attributes = array_merge($options, ['class' => 'btn btn-primary fw-bold', 'name' => $name, 'type' => 'submit']); |
||
| 81 | |||
| 82 | return Form::button('<i class="mdi mdi-check-bold fw-bold"></i> '.$value, $attributes); |
||
| 83 | }); |
||
| 84 | |||
| 85 | Form::macro('nCancel', function ($title, $options = []) { |
||
| 86 | $attributes = array_merge($options, ['class' => 'btn btn-danger fw-bold']); |
||
| 87 | |||
| 88 | return Html::link(URL::previous(), '<i class="mdi mdi-close-outline fw-bolder"></i> '.$title, $attributes, null, false); |
||
| 89 | }); |
||
| 92 |