| Conditions | 7 |
| Paths | 36 |
| Total Lines | 63 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 declare(strict_types=1); |
||
| 14 | public function editable($value, Field $field, HTMLElement $previous): HTMLElement |
||
| 15 | { |
||
| 16 | $renderable = $field->getRenderables(); |
||
| 17 | $validators = $field->getValidators(); |
||
| 18 | |||
| 19 | $inputAtts = [ |
||
| 20 | 'name' => $field->getName(), |
||
| 21 | 'v-model' => $field->getName(), |
||
| 22 | 'drag-drop' => '' |
||
| 23 | ]; |
||
| 24 | if ($renderable[File::ACCEPT] ?? false) { |
||
| 25 | if (is_array($renderable[File::ACCEPT])) { |
||
| 26 | $accept = join(',', $renderable[File::ACCEPT]); |
||
| 27 | } else { |
||
| 28 | $accept = $renderable[File::ACCEPT]; |
||
| 29 | } |
||
| 30 | $inputAtts['accept'] = htmlspecialchars($accept); |
||
| 31 | } |
||
| 32 | if ($validators[Datatype::REQUIRED] ?? false) { |
||
| 33 | $inputAtts['required'] = 'required'; |
||
| 34 | } |
||
| 35 | if ($validators[File::MAX_SIZE] ?? false) { |
||
| 36 | $inputAtts['data-max-size'] = $validators[File::MAX_SIZE]; |
||
| 37 | } |
||
| 38 | foreach ([static::DISABLED, static::READONLY] as $v) { |
||
| 39 | if ($field->getRenderable($v, false)) { |
||
| 40 | $inputAtts[$v] = true; |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | $container = HTMLElement::factory( |
||
| 45 | 'b-field', |
||
| 46 | [], |
||
| 47 | HTMLElement::factory( |
||
| 48 | 'b-upload', |
||
| 49 | $inputAtts, |
||
| 50 | HTMLElement::factory( |
||
| 51 | 'section', |
||
| 52 | ['class' => 'section'], |
||
| 53 | HTMLElement::factory( |
||
| 54 | 'div', |
||
| 55 | ['class' => "content has-text-centered"], |
||
| 56 | [ |
||
| 57 | HTMLElement::factory( |
||
| 58 | 'p', |
||
| 59 | [], |
||
| 60 | HTMLElement::factory( |
||
| 61 | 'b-icon', |
||
| 62 | [ 'icon' => "upload", 'size' => "is-large" ] |
||
| 63 | ) |
||
| 64 | ), |
||
| 65 | HTMLElement::factory( |
||
| 66 | 'p', |
||
| 67 | [ 'class' => 'formularium-label'], |
||
| 68 | $renderable[Renderable::LABEL] ?? '' |
||
| 69 | ) |
||
| 70 | ] |
||
| 71 | ) |
||
| 72 | ) |
||
| 73 | ) |
||
| 74 | ); |
||
| 75 | |||
| 76 | return $container; |
||
| 77 | } |
||
| 109 |