| Conditions | 12 |
| Paths | 1 |
| Total Lines | 42 |
| Code Lines | 29 |
| 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); |
||
| 20 | public function fix($value, Field $field, HTMLElement $previous): HTMLElement |
||
|
|
|||
| 21 | { |
||
| 22 | $previous->walk(function (HTMLElement $element) use ($field) { |
||
| 23 | if ($element->getTag() === 'input') { |
||
| 24 | if ($element->getAttribute('type') === ['checkbox']) { |
||
| 25 | $element->setAttribute('checked', "{this.state.{$field->getName()}}"); |
||
| 26 | } else { |
||
| 27 | $element->setAttribute('value', "{this.state.{$field->getName()}}"); |
||
| 28 | } |
||
| 29 | $element->setAttribute('onChange', '{this.handleInputChange}'); |
||
| 30 | } |
||
| 31 | if ($element->getTag() === 'textarea' || $element->getTag() === 'select') { |
||
| 32 | $element->setAttribute('value', "{this.state.{$field->getName()}}"); |
||
| 33 | $element->setAttribute('onChange', '{this.handleInputChange}'); |
||
| 34 | } |
||
| 35 | if ($element->getTag() === 'select') { |
||
| 36 | $options = $element->get('[selected=selected]'); |
||
| 37 | if (!empty($options)) { |
||
| 38 | $element->setAttribute('value', $options[0]->getAttribute('value')[0]); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | if ($element->getTag() === 'option') { |
||
| 42 | $element->removeAttribute('selected'); |
||
| 43 | } |
||
| 44 | if ($element->hasAttribute('for')) { |
||
| 45 | $element->setAttribute('htmlFor', $element->getAttribute('for')); |
||
| 46 | $element->removeAttribute('for'); |
||
| 47 | } |
||
| 48 | if ($element->hasAttribute('class')) { |
||
| 49 | $element->setAttribute('className', $element->getAttribute('class')); |
||
| 50 | $element->removeAttribute('class'); |
||
| 51 | } |
||
| 52 | if (!empty($element->getAttribute('minlength'))) { |
||
| 53 | $element->setAttribute('minLength', $element->getAttribute('minlength')); |
||
| 54 | $element->removeAttribute('minlength'); |
||
| 55 | } |
||
| 56 | if (!empty($element->getAttribute('maxlength'))) { |
||
| 57 | $element->setAttribute('maxLength', $element->getAttribute('maxlength')); |
||
| 58 | $element->removeAttribute('maxlength'); |
||
| 59 | } |
||
| 60 | }); |
||
| 61 | return $previous; |
||
| 62 | } |
||
| 64 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.