| Conditions | 12 |
| Paths | 12 |
| Total Lines | 38 |
| Code Lines | 32 |
| 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 |
||
| 30 | public function updateAttributes(&$attributes) |
||
| 31 | { |
||
| 32 | $class = $attributes['class'] ?? ''; |
||
| 33 | $o = $this->owner; |
||
| 34 | |||
| 35 | //TODO: check if this is needed at all?? |
||
| 36 | switch (true) { |
||
| 37 | case $o instanceof ReadonlyField: |
||
| 38 | $class = 'form-control ' . $class; |
||
| 39 | break; |
||
| 40 | case $o instanceof FormAction: |
||
| 41 | $class = 'btn ' . $class; |
||
| 42 | if (strpos($class, 'btn-') === false) { |
||
| 43 | $class .= " btn-primary"; |
||
| 44 | } |
||
| 45 | break; |
||
| 46 | case $o instanceof CheckboxSetField: |
||
| 47 | case $o instanceof OptionsetField: |
||
| 48 | $class = 'list-unstyled ' . $class; |
||
| 49 | break; |
||
| 50 | case $o instanceof CheckboxField: |
||
| 51 | $class = 'form-check-input ' . $class; |
||
| 52 | break; |
||
| 53 | case $o instanceof TabSet: |
||
| 54 | $class = 'tab-content ' . $class; |
||
| 55 | break; |
||
| 56 | case $o instanceof Tab: |
||
| 57 | $class = 'tab-pane ' . $class; |
||
| 58 | break; |
||
| 59 | case $o instanceof SelectField: |
||
| 60 | $class = 'form-select ' . $class; |
||
| 61 | break; |
||
| 62 | case $o instanceof TextField: |
||
| 63 | case $o instanceof TextareaField: |
||
| 64 | $class = 'form-control ' . $class; |
||
| 65 | break; |
||
| 66 | } |
||
| 67 | $attributes['class'] = trim($class); |
||
| 68 | } |
||
| 78 |