Conditions | 16 |
Paths | 28 |
Total Lines | 60 |
Code Lines | 44 |
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 |
||
19 | public static function generateHTML(GeneratorField $field, $templateType, $localized = false) |
||
20 | { |
||
21 | $fieldTemplate = ''; |
||
22 | |||
23 | $localized = (true === $localized) ? '_locale' : ''; |
||
24 | switch ($field->htmlType) { |
||
25 | case 'text': |
||
26 | case 'textarea': |
||
27 | case 'date': |
||
28 | case 'file': |
||
29 | case 'email': |
||
30 | case 'password': |
||
31 | case 'number': |
||
32 | $fieldTemplate = get_template('scaffold.vues.fields.'.$field->htmlType.$localized, $templateType); |
||
33 | |||
34 | break; |
||
35 | case 'select': |
||
36 | case 'enum': |
||
37 | $fieldTemplate = get_template('scaffold.vues.fields.select'.$localized, $templateType); |
||
38 | $radioLabels = GeneratorFieldsInputUtil::prepareKeyValueArrFromLabelValueStr($field->htmlValues); |
||
39 | |||
40 | $fieldTemplate = str_replace( |
||
41 | '$INPUT_ARR$', |
||
42 | GeneratorFieldsInputUtil::prepareKeyValueArrayStr($radioLabels), |
||
43 | $fieldTemplate |
||
44 | ); |
||
45 | |||
46 | break; |
||
47 | case 'checkbox': |
||
48 | $fieldTemplate = get_template('scaffold.vues.fields.checkbox'.$localized, $templateType); |
||
49 | if (count($field->htmlValues) > 0) { |
||
50 | $checkboxValue = $field->htmlValues[0]; |
||
51 | } else { |
||
52 | $checkboxValue = 1; |
||
53 | } |
||
54 | $fieldTemplate = str_replace('$CHECKBOX_VALUE$', $checkboxValue, $fieldTemplate); |
||
55 | |||
56 | break; |
||
57 | case 'radio': |
||
58 | $fieldTemplate = get_template('scaffold.vues.fields.radio_group'.$localized, $templateType); |
||
59 | $radioTemplate = get_template('scaffold.vues.fields.radio'.$localized, $templateType); |
||
60 | |||
61 | $radioLabels = GeneratorFieldsInputUtil::prepareKeyValueArrFromLabelValueStr($field->htmlValues); |
||
62 | |||
63 | $radioButtons = []; |
||
64 | foreach ($radioLabels as $label => $value) { |
||
65 | $radioButtonTemplate = str_replace('$LABEL$', $label, $radioTemplate); |
||
66 | $radioButtonTemplate = str_replace('$VALUE$', $value, $radioButtonTemplate); |
||
67 | $radioButtons[] = $radioButtonTemplate; |
||
68 | } |
||
69 | $fieldTemplate = str_replace('$RADIO_BUTTONS$', implode("\n", $radioButtons), $fieldTemplate); |
||
70 | |||
71 | break; |
||
72 | case 'toggle-switch': |
||
73 | $fieldTemplate = get_template('scaffold.vues.fields.toggle-switch'.$localized, $templateType); |
||
74 | |||
75 | break; |
||
76 | } |
||
77 | |||
78 | return $fieldTemplate; |
||
79 | } |
||
81 |