Conditions | 14 |
Paths | 14 |
Total Lines | 29 |
Code Lines | 26 |
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 |
||
44 | private function setField(string $fieldName, string $fieldType, mixed $value): void |
||
45 | { |
||
46 | $setter = 'set' . ucfirst($fieldName); |
||
47 | |||
48 | switch ($fieldType) { |
||
49 | case 'checkbox': |
||
50 | $this->$setter((bool) $value); |
||
51 | break; |
||
52 | case 'email': |
||
53 | case 'file': |
||
54 | case 'hidden': |
||
55 | case 'password': |
||
56 | case 'string': |
||
57 | case 'text': |
||
58 | case 'textarea': |
||
59 | $this->$setter((string) $value); |
||
60 | break; |
||
61 | case 'integer': |
||
62 | $this->$setter((int) $value); |
||
63 | break; |
||
64 | case 'float': |
||
65 | $this->$setter((float) $value); |
||
66 | break; |
||
67 | case 'multiselect': |
||
68 | case 'radio': |
||
69 | case 'select': |
||
70 | default: |
||
71 | $this->$setter($value); |
||
72 | break; |
||
73 | } |
||
76 |