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