Conditions | 12 |
Paths | 11 |
Total Lines | 47 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 1 |
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 |
||
91 | private static function fieldByType($field, $field_value, $attributes = [], $errors = []): string |
||
92 | { |
||
93 | $ret = null; |
||
94 | if ($field->isAutoIncremented()) { |
||
95 | $ret = Form::hidden($field->name(), $field_value); |
||
96 | } |
||
97 | elseif ($field->type()->isBoolean()) { |
||
98 | $option_list = $attributes['values'] ?? [0 => 0, 1 => 1]; |
||
99 | $ret = Form::select($field->name(), $option_list, $field_value, $attributes); // |
||
100 | } |
||
101 | elseif ($field->type()->isInteger()) { |
||
102 | $ret = Form::input($field->name(), $field_value, $attributes, $errors); |
||
103 | } |
||
104 | elseif ($field->type()->isYear()) { |
||
105 | $attributes['size'] = $attributes['maxlength'] = 4; |
||
106 | $ret = Form::input($field->name(), $field_value, $attributes, $errors); |
||
107 | } |
||
108 | elseif ($field->type()->isDate()) { |
||
109 | $ret = Form::date($field->name(), $field_value, $attributes, $errors); |
||
110 | } |
||
111 | elseif ($field->type()->isTime()) { |
||
112 | $ret = Form::time($field->name(), $field_value, $attributes, $errors); |
||
113 | } |
||
114 | elseif ($field->type()->isDatetime()) { |
||
115 | $ret = Form::datetime($field->name(), $field_value, $attributes, $errors); |
||
116 | } |
||
117 | elseif ($field->type()->isText()) { |
||
118 | $ret = Form::textarea($field->name(), $field_value, $attributes, $errors); |
||
119 | } |
||
120 | elseif ($field->type()->isEnum()) { |
||
121 | $enum_values = []; |
||
122 | foreach ($field->type()->getEnumValues() as $e_val) { |
||
123 | $enum_values[$e_val] = $e_val; |
||
124 | } |
||
125 | |||
126 | $selected = $attributes['value'] ?? $field_value ?? ''; |
||
127 | $ret = Form::select($field->name(), $enum_values, $selected, $attributes); // |
||
128 | } |
||
129 | elseif ($field->type()->isString()) { |
||
130 | $max_length = $field->type()->getLength(); |
||
131 | $attributes['size'] = $attributes['maxlength'] = $max_length; |
||
132 | $ret = Form::input($field->name(), $field_value, $attributes, $errors); |
||
133 | } |
||
134 | else |
||
135 | $ret = Form::input($field->name(), $field_value, $attributes, $errors); |
||
136 | |||
137 | return $ret; |
||
138 | } |
||
155 |