Conditions | 51 |
Paths | 54 |
Total Lines | 201 |
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 |
||
53 | function renderInputForm($key, $type) |
||
54 | { |
||
55 | global $PMF_LANG, $faqConfig; |
||
56 | |||
57 | switch ($type) { |
||
58 | |||
59 | case 'area': |
||
60 | printf( |
||
61 | '<textarea name="edit[%s]" rows="4" class="form-control">%s</textarea>', |
||
62 | $key, |
||
63 | str_replace('<', '<', str_replace('>', '>', $faqConfig->get($key))) |
||
64 | ); |
||
65 | printf("</div>\n"); |
||
66 | break; |
||
67 | |||
68 | case 'input': |
||
69 | if ('' == $faqConfig->get($key) && 'socialnetworks.twitterAccessTokenKey' == $key && |
||
70 | isset($_SESSION['access_token'])) { |
||
71 | $value = $_SESSION['access_token']['oauth_token']; |
||
72 | } elseif ('' == $faqConfig->get($key) && 'socialnetworks.twitterAccessTokenSecret' == $key && |
||
73 | isset($_SESSION['access_token'])) { |
||
74 | $value = $_SESSION['access_token']['oauth_token_secret']; |
||
75 | } else { |
||
76 | $value = str_replace('"', '"', $faqConfig->get($key)); |
||
77 | } |
||
78 | printf( |
||
79 | '<input class="form-control" type="%s" name="edit[%s]" value="%s" step="1" min="0">', |
||
80 | is_numeric($value) ? 'number' : 'text', |
||
81 | $key, |
||
82 | $value |
||
83 | ); |
||
84 | echo "</div>\n"; |
||
85 | break; |
||
86 | |||
87 | case 'password': |
||
88 | printf( |
||
89 | '<input class="form-control" type="password" name="edit[%s]" value="%s">', |
||
90 | $key, |
||
91 | $faqConfig->get($key) |
||
92 | ); |
||
93 | echo "</div>\n"; |
||
94 | break; |
||
95 | |||
96 | case 'select': |
||
97 | printf('<select name="edit[%s]" class="form-control">', $key); |
||
98 | |||
99 | switch ($key) { |
||
100 | |||
101 | case 'main.language': |
||
102 | $languages = Language::getAvailableLanguages(); |
||
103 | if (count($languages) > 0) { |
||
104 | echo Language::languageOptions( |
||
105 | str_replace( |
||
106 | array( |
||
107 | 'language_', |
||
108 | '.php', |
||
109 | ), |
||
110 | '', |
||
111 | $faqConfig->get('main.language') |
||
112 | ), |
||
113 | false, |
||
114 | true |
||
115 | ); |
||
116 | } else { |
||
117 | echo '<option value="language_en.php">English</option>'; |
||
118 | } |
||
119 | break; |
||
120 | |||
121 | case 'records.orderby': |
||
122 | echo Configuration::sortingOptions($faqConfig->get($key)); |
||
123 | break; |
||
124 | |||
125 | case 'records.sortby': |
||
126 | printf( |
||
127 | '<option value="DESC" %s>%s</option>', |
||
128 | ('DESC' == $faqConfig->get($key)) ? 'selected' : '', |
||
129 | $PMF_LANG['ad_conf_desc'] |
||
130 | ); |
||
131 | printf( |
||
132 | '<option value="ASC" %s>%s</option>', |
||
133 | ('ASC' == $faqConfig->get($key)) ? 'selected' : '', |
||
134 | $PMF_LANG['ad_conf_asc'] |
||
135 | ); |
||
136 | break; |
||
137 | |||
138 | case 'security.permLevel': |
||
139 | echo PermissionHelper::permOptions($faqConfig->get($key)); |
||
140 | break; |
||
141 | |||
142 | case 'main.templateSet': |
||
143 | $faqSystem = new System(); |
||
144 | $templates = $faqSystem->getAvailableTemplates(); |
||
145 | |||
146 | foreach ($templates as $template => $selected) { |
||
147 | printf('<option%s>%s</option>', |
||
148 | ($selected === true ? ' selected' : ''), |
||
149 | $template |
||
150 | ); |
||
151 | } |
||
152 | break; |
||
153 | |||
154 | case 'records.attachmentsStorageType': |
||
155 | foreach ($PMF_LANG['att_storage_type'] as $i => $item) { |
||
156 | $selected = (int)$faqConfig->get($key) === $i ? ' selected' : ''; |
||
157 | printf('<option value="%d"%s>%s</option>', $i, $selected, $item); |
||
158 | } |
||
159 | break; |
||
160 | |||
161 | case 'records.orderingPopularFaqs': |
||
162 | printf( |
||
163 | '<option value="visits"%s>%s</option>', |
||
164 | ('visits' === $faqConfig->get($key)) ? ' selected' : '', |
||
165 | $PMF_LANG['records.orderingPopularFaqs.visits'] |
||
166 | ); |
||
167 | printf( |
||
168 | '<option value="voting"%s>%s</option>', |
||
169 | ('voting' === $faqConfig->get($key)) ? ' selected' : '', |
||
170 | $PMF_LANG['records.orderingPopularFaqs.voting'] |
||
171 | ); |
||
172 | break; |
||
173 | |||
174 | case 'search.relevance': |
||
175 | printf( |
||
176 | '<option value="thema,content,keywords"%s>%s</option>', |
||
177 | ('thema,content,keywords' == $faqConfig->get($key)) ? ' selected' : '', |
||
178 | $PMF_LANG['search.relevance.thema-content-keywords'] |
||
179 | ); |
||
180 | printf( |
||
181 | '<option value="thema,keywords,content"%s>%s</option>', |
||
182 | ( |
||
183 | 'thema,keywords,content' == $faqConfig->get($key)) ? ' selected' : '', |
||
184 | $PMF_LANG['search.relevance.thema-keywords-content'] |
||
185 | ); |
||
186 | printf( |
||
187 | '<option value="content,thema,keywords"%s>%s</option>', |
||
188 | ('content,thema,keywords' == $faqConfig->get($key)) ? ' selected' : '', |
||
189 | $PMF_LANG['search.relevance.content-thema-keywords'] |
||
190 | ); |
||
191 | printf( |
||
192 | '<option value="content,keywords,thema"%s>%s</option>', |
||
193 | ('content,keywords,thema' == $faqConfig->get($key)) ? ' selected' : '', |
||
194 | $PMF_LANG['search.relevance.content-keywords-thema'] |
||
195 | ); |
||
196 | printf( |
||
197 | '<option value="keywords,content,thema"%s>%s</option>', |
||
198 | ('keywords,content,thema' == $faqConfig->get($key)) ? ' selected' : '', |
||
199 | $PMF_LANG['search.relevance.keywords-content-thema'] |
||
200 | ); |
||
201 | printf( |
||
202 | '<option value="keywords,thema,content"%s>%s</option>', |
||
203 | ('keywords,thema,content' == $faqConfig->get($key)) ? ' selected' : '', |
||
204 | $PMF_LANG['search.relevance.keywords-thema-content'] |
||
205 | ); |
||
206 | break; |
||
207 | |||
208 | case 'seo.metaTagsHome': |
||
209 | case 'seo.metaTagsFaqs': |
||
210 | case 'seo.metaTagsCategories': |
||
211 | case 'seo.metaTagsPages': |
||
212 | case 'seo.metaTagsAdmin': |
||
213 | $adminHelper = new Administration(); |
||
214 | echo $adminHelper->renderMetaRobotsDropdown($faqConfig->get($key)); |
||
215 | break; |
||
216 | } |
||
217 | |||
218 | echo "</select>\n</div>\n"; |
||
219 | break; |
||
220 | |||
221 | case 'checkbox': |
||
222 | printf( |
||
223 | '<div class="form-check"><input class="form-check-input" type="checkbox" name="edit[%s]" value="true"', |
||
224 | $key |
||
225 | ); |
||
226 | if ($faqConfig->get($key)) { |
||
227 | echo ' checked'; |
||
228 | } |
||
229 | if ('ldap.ldapSupport' === $key && !extension_loaded('ldap')) { |
||
230 | echo ' disabled'; |
||
231 | } |
||
232 | if ('security.useSslForLogins' === $key && empty($_SERVER['HTTPS'])) { |
||
233 | echo ' disabled'; |
||
234 | } |
||
235 | if ('security.useSslOnly' === $key && empty($_SERVER['HTTPS'])) { |
||
236 | echo ' disabled'; |
||
237 | } |
||
238 | if ('security.ssoSupport' === $key && empty($_SERVER['REMOTE_USER'])) { |
||
239 | echo ' disabled'; |
||
240 | } |
||
241 | echo '></div></div>'; |
||
242 | break; |
||
243 | |||
244 | case 'print': |
||
245 | printf( |
||
246 | '<input type="text" readonly name="edit[%s]" class="form-control-plaintext" value="%s"></div>', |
||
247 | $key, |
||
248 | str_replace('"', '"', $faqConfig->get($key)), |
||
249 | $faqConfig->get($key) |
||
250 | ); |
||
251 | break; |
||
252 | } |
||
253 | } |
||
254 | |||
313 |