| Conditions | 7 |
| Paths | 19 |
| Total Lines | 59 |
| Code Lines | 40 |
| 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 declare(strict_types=1); |
||
| 38 | public function bootstrapify($value, Field $field, HTMLNode $previous, string $tag = 'input'): HTMLNode |
||
| 39 | { |
||
| 40 | // add extra classes |
||
| 41 | $input = $previous->get($tag); |
||
| 42 | if (empty($input)) { |
||
| 43 | return $previous; |
||
| 44 | } |
||
| 45 | $input = $input[0]; |
||
| 46 | $input->addAttributes([ |
||
| 47 | 'class' => 'form-control', |
||
| 48 | ]); |
||
| 49 | $comment = $previous->get('.formularium-comment'); |
||
| 50 | if (!empty($comment)) { |
||
| 51 | $comment[0]->setTag('small')->addAttributes([ |
||
| 52 | 'class' => 'form-text text-muted', |
||
| 53 | ]); |
||
| 54 | } |
||
| 55 | $size = $field->getRenderable(Renderable::SIZE, ''); |
||
| 56 | switch ($size) { |
||
| 57 | case Renderable::SIZE_LARGE: |
||
| 58 | $input->addAttribute('class', 'form-control-lg'); |
||
| 59 | break; |
||
| 60 | case Renderable::SIZE_SMALL: |
||
| 61 | $input->addAttribute('class', 'form-control-sm'); |
||
| 62 | break; |
||
| 63 | } |
||
| 64 | |||
| 65 | $icon = $field->getRenderable(Renderable::ICON, ''); |
||
| 66 | if ($icon) { |
||
| 67 | $iconData = []; |
||
| 68 | $iconPack = $field->getRenderable(Renderable::ICON_PACK, ''); |
||
| 69 | if ($iconPack) { |
||
| 70 | $iconData[] = $iconPack; |
||
| 71 | } |
||
| 72 | $iconData[] = $icon; |
||
| 73 | $group = HTMLNode::factory( |
||
| 74 | 'div', |
||
| 75 | [ 'class' => "input-group mb-3" ], |
||
| 76 | [ |
||
| 77 | HTMLNode::factory( |
||
| 78 | 'div', |
||
| 79 | [ 'class' => "input-group-prepend" ], |
||
| 80 | HTMLNode::factory( |
||
| 81 | 'span', |
||
| 82 | [ 'class' => "input-group-text" ], |
||
| 83 | HTMLNode::factory( |
||
| 84 | 'i', |
||
| 85 | [ 'class' => $iconData ], |
||
| 86 | [] |
||
| 87 | ) |
||
| 88 | ) |
||
| 89 | ), |
||
| 90 | clone $input |
||
| 91 | ] |
||
| 92 | ); |
||
| 93 | $input->replace($group); |
||
| 94 | } |
||
| 95 | |||
| 96 | return $previous; |
||
| 97 | } |
||
| 99 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.