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