Conditions | 12 |
Paths | 2048 |
Total Lines | 47 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 declare(strict_types=1); |
||
151 | public function saveField($vars, $weight = 0): string |
||
152 | { |
||
153 | $field = $this->createField(); |
||
154 | $field->setVar('field_name', $vars['name']); |
||
155 | $field->setVar('field_valuetype', $vars['valuetype']); |
||
156 | $field->setVar('field_type', $vars['type']); |
||
157 | $field->setVar('field_weight', $weight); |
||
158 | if (isset($vars['title'])) { |
||
159 | $field->setVar('field_title', $vars['title']); |
||
160 | } |
||
161 | if (isset($vars['description'])) { |
||
162 | $field->setVar('field_description', $vars['description']); |
||
163 | } |
||
164 | if (isset($vars['required'])) { |
||
165 | $field->setVar('field_required', $vars['required']); //0 = no, 1 = yes |
||
166 | } |
||
167 | if (isset($vars['maxlength'])) { |
||
168 | $field->setVar('field_maxlength', $vars['maxlength']); |
||
169 | } |
||
170 | if (isset($vars['default'])) { |
||
171 | $field->setVar('field_default', $vars['default']); |
||
172 | } |
||
173 | if (isset($vars['notnull'])) { |
||
174 | $field->setVar('field_notnull', $vars['notnull']); |
||
175 | } |
||
176 | if (isset($vars['show'])) { |
||
177 | $field->setVar('field_show', $vars['show']); |
||
178 | } |
||
179 | if (isset($vars['edit'])) { |
||
180 | $field->setVar('field_edit', $vars['edit']); |
||
181 | } |
||
182 | if (isset($vars['config'])) { |
||
183 | $field->setVar('field_config', $vars['config']); |
||
184 | } |
||
185 | if (isset($vars['options'])) { |
||
186 | $field->setVar('field_options', $vars['options']); |
||
187 | } else { |
||
188 | $field->setVar('field_options', []); |
||
189 | } |
||
190 | if ($this->insertField($field)) { |
||
191 | $msg = ' Field <b>' . $vars['name'] . '</b> added to the database'; |
||
192 | } else { |
||
193 | $msg = ' <span style="color:#ff0000;">ERROR: Could not insert field <b>' . $vars['name'] . '</b> into the database. ' . \implode(' ', $field->getErrors()) . $this->db->error() . '</span>'; |
||
194 | } |
||
195 | unset($field); |
||
196 | |||
197 | return $msg; |
||
198 | } |
||
224 |