| Conditions | 15 |
| Paths | 15 |
| Total Lines | 44 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 85 | protected function prepareField($field, $type, array $settings) |
||
| 86 | { |
||
| 87 | $options = ArrayHelper::getValue($settings, 'options', []); |
||
| 88 | switch ($type) { |
||
| 89 | case static::INPUT_HIDDEN: |
||
| 90 | case static::INPUT_TEXT: |
||
| 91 | case static::INPUT_TEXTAREA: |
||
| 92 | case static::INPUT_PASSWORD: |
||
| 93 | case static::INPUT_FILE: |
||
| 94 | $field->$type($options); |
||
| 95 | break; |
||
| 96 | |||
| 97 | case static::INPUT_DROPDOWN_LIST: |
||
| 98 | case static::INPUT_LIST_BOX: |
||
| 99 | case static::INPUT_CHECKBOX_LIST: |
||
| 100 | case static::INPUT_RADIO_LIST: |
||
| 101 | $items = ArrayHelper::getValue($settings, 'items', []); |
||
| 102 | $field->$type($items, $options); |
||
| 103 | break; |
||
| 104 | |||
| 105 | case static::INPUT_CHECKBOX: |
||
| 106 | case static::INPUT_RADIO: |
||
| 107 | $enclosedByLabel = ArrayHelper::getValue($settings, 'enclosedByLabel', true); |
||
| 108 | $field->$type($options, $enclosedByLabel); |
||
| 109 | break; |
||
| 110 | |||
| 111 | case static::INPUT_HTML5: |
||
| 112 | $html5type = ArrayHelper::getValue($settings, 'html5type', 'text'); |
||
| 113 | $field->$type($html5type, $options); |
||
| 114 | break; |
||
| 115 | |||
| 116 | case static::INPUT_WIDGET: |
||
| 117 | $widgetClass = $this->getWidgetClass($settings); |
||
| 118 | $field->$type($widgetClass, $options); |
||
| 119 | break; |
||
| 120 | |||
| 121 | case static::INPUT_RAW: |
||
| 122 | $field->parts['{input}'] = $this->getValue($settings); |
||
| 123 | break; |
||
| 124 | |||
| 125 | default: |
||
| 126 | throw new InvalidConfigException("Invalid input type '{$type}' configured for the attribute."); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 161 |