| Conditions | 10 |
| Paths | 1 |
| Total Lines | 44 |
| Code Lines | 31 |
| 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); |
||
| 26 | public function _editable($value, Field $field, HTMLNode $previous): HTMLNode |
||
| 27 | { |
||
| 28 | // add extra classes |
||
| 29 | $previous->walk( |
||
| 30 | function ($e) use ($field) { |
||
| 31 | if ($e instanceof HTMLNode) { |
||
| 32 | if ($e->getTag() === 'input') { |
||
| 33 | if (($e->getAttribute('type')[0] ?? '') === 'radio') { |
||
| 34 | $e->setTag('b-radio') |
||
| 35 | ->setAttribute('native-value', $e->getAttribute('value')) |
||
| 36 | ->setContent($e->getAttribute('title')); |
||
| 37 | } else { |
||
| 38 | $e->setTag('b-input'); |
||
| 39 | } |
||
| 40 | } elseif ($e->getTag() === 'select') { |
||
| 41 | $e->setTag('b-select'); |
||
| 42 | } elseif ($e->getTag() === 'textarea') { |
||
| 43 | $e->setTag('b-input')->setAttribute('type', 'textarea'); |
||
| 44 | } else { |
||
| 45 | return; |
||
| 46 | } |
||
| 47 | |||
| 48 | $size = $field->getRenderable(Renderable::SIZE, ''); |
||
| 49 | switch ($size) { |
||
| 50 | case Renderable::SIZE_LARGE: |
||
| 51 | $e->addAttribute('size', 'is-large'); |
||
| 52 | break; |
||
| 53 | case Renderable::SIZE_SMALL: |
||
| 54 | $e->addAttribute('size', 'is-small'); |
||
| 55 | break; |
||
| 56 | } |
||
| 57 | |||
| 58 | $icon = $field->getRenderable(Renderable::ICON, ''); |
||
| 59 | if ($icon) { |
||
| 60 | $e->addAttribute('icon', str_replace('fa-', '', $icon)); |
||
| 61 | } |
||
| 62 | $iconPack = $field->getRenderable(Renderable::ICON_PACK, ''); |
||
| 63 | if ($iconPack) { |
||
| 64 | $e->addAttribute('icon-pack', $iconPack); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | ); |
||
| 69 | return $previous; |
||
| 70 | } |
||
| 72 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.