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