Conditions | 30 |
Paths | 288 |
Total Lines | 112 |
Code Lines | 76 |
Lines | 16 |
Ratio | 14.29 % |
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 |
||
73 | private function render($data) { |
||
74 | global $modx, $_lang, $_country_lang; |
||
75 | |||
76 | $data['lang.name'] = (isset($_lang[$data['alias']]) ? $_lang[$data['alias']] : $data['alias']); |
||
77 | $data['value'] = (isset($_POST[$data['name']][$data['value']]) ? $_POST[$data['name']][$data['value']] : (isset($data['value']) ? $modx->htmlspecialchars($data['value']) : '')); |
||
78 | $data['readonly'] = ($data['readonly'] ? ' readonly' : ''); |
||
79 | |||
80 | $output = ''; |
||
81 | $output .= '<div class="form-group row">'; |
||
82 | |||
83 | switch($data['type']) { |
||
84 | |||
85 | case 'text': |
||
86 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label> |
||
87 | <div class="col-sm-7"> |
||
88 | <input type="text" name="[+name+]" class="form-control" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />'; |
||
89 | $output .= $data['content']; |
||
90 | $output .= '</div>'; |
||
91 | |||
92 | break; |
||
93 | |||
94 | case 'textarea': |
||
95 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label> |
||
96 | <div class="col-sm-7"> |
||
97 | <textarea name="[+name+]" class="form-control" id="[+name+]" onChange="documentDirty=true;"[+readonly+]>[+value+]</textarea>'; |
||
98 | $output .= $data['content']; |
||
99 | $output .= '</div>'; |
||
100 | |||
101 | break; |
||
102 | |||
103 | case 'date': |
||
104 | $data['value'] = (isset($_POST[$data['name']][$data['value']]) ? $modx->toDateFormat($_POST[$data['name']][$data['value']]) : (isset($data['value']) ? $modx->toDateFormat($data['value']) : '')); |
||
105 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label> |
||
106 | <div class="col-sm-7"> |
||
107 | <input type="text" name="[+name+]" class="form-control DatePicker" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />'; |
||
108 | $output .= $data['content']; |
||
109 | $output .= '</div>'; |
||
110 | |||
111 | break; |
||
112 | |||
113 | case 'select': |
||
114 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>'; |
||
115 | $output .= '<div class="col-sm-7">'; |
||
116 | $output .= '<select name="[+name+]" class="form-control" id="[+name+]" onChange="documentDirty=true;">'; |
||
117 | if($data['name'] == 'country' && isset($_country_lang)) { |
||
118 | $chosenCountry = isset($_POST['country']) ? $_POST['country'] : $data['country']; |
||
119 | $output .= '<option value=""' . (!isset($chosenCountry) ? ' selected' : '') . '> </option>'; |
||
120 | foreach($_country_lang as $key => $value) { |
||
121 | $output .= '<option value="' . $key . '"' . (isset($chosenCountry) && $chosenCountry == $key ? ' selected' : '') . '>' . $value . '</option>'; |
||
122 | } |
||
123 | View Code Duplication | } else { |
|
124 | if($data['elements']) { |
||
125 | $elements = explode('||', $data['elements']); |
||
126 | foreach($elements as $key => $value) { |
||
127 | $value = explode('==', $value); |
||
128 | $output .= '<option value="' . $value[1] . '">' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]) . '</option>'; |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | $output .= '</select>'; |
||
133 | $output .= $data['content']; |
||
134 | $output .= '</div>'; |
||
135 | |||
136 | break; |
||
137 | |||
138 | case 'checkbox': |
||
139 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>'; |
||
140 | $output .= '<div class="col-sm-7">'; |
||
141 | $output .= '<input type="checkbox" name="[+name+]" class="form-control" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />'; |
||
142 | if($data['elements']) { |
||
143 | $elements = explode('||', $data['elements']); |
||
144 | foreach($elements as $key => $value) { |
||
145 | $value = explode('==', $value); |
||
146 | $output .= '<br /><input type="checkbox" name="' . $value[0] . '" class="form-control" id="' . $value[0] . '" value="' . $value[1] . '" onChange="documentDirty=true;"[+readonly+] /> ' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]); |
||
147 | } |
||
148 | } |
||
149 | $output .= $data['content']; |
||
150 | $output .= '</div>'; |
||
151 | |||
152 | break; |
||
153 | |||
154 | case 'radio': |
||
155 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>'; |
||
156 | $output .= '<div class="col-sm-7">'; |
||
157 | $output .= '<input type="radio" name="[+name+]" class="form-control" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />'; |
||
158 | View Code Duplication | if($data['elements']) { |
|
159 | $elements = explode('||', $data['elements']); |
||
160 | foreach($elements as $key => $value) { |
||
161 | $value = explode('==', $value); |
||
162 | $output .= '<br /><input type="radio" name="[+name+]" class="form-control" id="[+name+]_' . $key . '" value="' . $value[1] . '" onChange="documentDirty=true;"[+readonly+] /> ' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]); |
||
163 | } |
||
164 | } |
||
165 | $output .= $data['content']; |
||
166 | $output .= '</div>'; |
||
167 | |||
168 | break; |
||
169 | |||
170 | case 'custom': |
||
171 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>'; |
||
172 | $output .= '<div class="col-sm-7">'; |
||
173 | $output .= $data['content']; |
||
174 | $output .= '</div>'; |
||
175 | |||
176 | break; |
||
177 | } |
||
178 | |||
179 | $output .= '</div>'; |
||
180 | |||
181 | $output = $modx->parseText($output, $data); |
||
182 | |||
183 | return $output; |
||
184 | } |
||
185 | |||
265 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.