Conditions | 9 |
Paths | 26 |
Total Lines | 55 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 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); |
||
57 | protected function editableRadio($value, Field $field, HTMLNode $previous): HTMLNode |
||
|
|||
58 | { |
||
59 | if (empty($value) && array_key_exists(static::DEFAULTVALUE, $field->getRenderables())) { |
||
60 | $value = $field->getRenderables()[static::DEFAULTVALUE]; |
||
61 | } |
||
62 | |||
63 | $element = new HTMLNode($this->framework->getEditableContainerTag(), ['class' => 'formularium-radio-group']); |
||
64 | |||
65 | /** |
||
66 | * @var Datatype_enum $datatype |
||
67 | */ |
||
68 | $datatype = $field->getDatatype(); |
||
69 | foreach ($datatype->getChoices() as $v => $label) { |
||
70 | $input = new HTMLNode('input'); |
||
71 | |||
72 | // send ids to delete/edit data later correctly. |
||
73 | if ($value !== null && $v == $value) { |
||
74 | $input->addAttribute('checked', 'checked'); |
||
75 | } |
||
76 | $elementname = $field->getName(); // 'loh:' . $this->name . '[' . $attrid . '][value]' . '[' . $attrid . ']'; |
||
77 | $id = $field->getName() . Framework::counter(); |
||
78 | $input->addAttributes([ |
||
79 | 'id' => $id, |
||
80 | 'name' => $elementname, |
||
81 | 'data-attribute' => $field->getName(), |
||
82 | 'data-datatype' => $datatype->getName(), |
||
83 | 'data-basetype' => $datatype->getBasetype(), |
||
84 | 'value' => $value, |
||
85 | 'type' => 'radio', |
||
86 | 'title' => $label |
||
87 | ]); |
||
88 | |||
89 | if ($field->getValidators()[Datatype::REQUIRED] ?? false) { |
||
90 | $element->setAttribute('required', 'required'); |
||
91 | } |
||
92 | foreach ([static::DISABLED, static::READONLY] as $p) { |
||
93 | if ($field->getRenderable($p, false)) { |
||
94 | $input->setAttribute($p, $p); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | $li = new HTMLNode( |
||
99 | 'div', |
||
100 | [ |
||
101 | 'class' => 'formularium-radio-item' |
||
102 | ], |
||
103 | [ |
||
104 | $input, |
||
105 | new HTMLNode('label', ['class' => 'formularium-radio-label', 'for' => $id], [HTMLNode::factory('span', [], $label)]) |
||
106 | ] |
||
107 | ); |
||
108 | $element->addContent($li); |
||
109 | } |
||
110 | |||
111 | return $element; |
||
112 | } |
||
162 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.