| Conditions | 16 |
| Paths | 16 |
| Total Lines | 31 |
| Code Lines | 28 |
| 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 |
||
| 51 | private function setField(string $fieldName, string $fieldType, mixed $value): void |
||
| 52 | { |
||
| 53 | $setter = 'set' . ucfirst($fieldName); |
||
| 54 | |||
| 55 | switch ($fieldType) { |
||
| 56 | case 'checkbox': |
||
| 57 | $this->$setter((bool) $value); |
||
| 58 | break; |
||
| 59 | case 'email': |
||
| 60 | case 'file': |
||
| 61 | case 'hidden': |
||
| 62 | case 'password': |
||
| 63 | case 'string': |
||
| 64 | case 'text': |
||
| 65 | case 'textarea': |
||
| 66 | $this->$setter((string) $value); |
||
| 67 | break; |
||
| 68 | case 'integer': |
||
| 69 | $this->$setter((int) $value); |
||
| 70 | break; |
||
| 71 | case 'float': |
||
| 72 | $this->$setter((float) $value); |
||
| 73 | break; |
||
| 74 | case 'date': |
||
| 75 | case 'datetime': |
||
| 76 | case 'multiselect': |
||
| 77 | case 'radio': |
||
| 78 | case 'select': |
||
| 79 | default: |
||
| 80 | $this->$setter($value); |
||
| 81 | break; |
||
| 82 | } |
||
| 85 |