Conditions | 43 |
Paths | 32 |
Total Lines | 162 |
Code Lines | 125 |
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 |
||
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 'select': |
||
93 | printf('<select name="edit[%s]" size="1" class="form-control">', $key); |
||
94 | |||
95 | switch ($key) { |
||
96 | |||
97 | case 'main.language': |
||
98 | $languages = PMF_Language::getAvailableLanguages(); |
||
99 | if (count($languages) > 0) { |
||
100 | echo PMF_Language::languageOptions( |
||
101 | str_replace( |
||
102 | array( |
||
103 | 'language_', |
||
104 | '.php' |
||
105 | ), |
||
106 | '', |
||
107 | $faqConfig->get('main.language') |
||
108 | ), |
||
109 | false, |
||
110 | true |
||
111 | ); |
||
112 | } else { |
||
113 | echo '<option value="language_en.php">English</option>'; |
||
114 | } |
||
115 | break; |
||
116 | |||
117 | case 'records.orderby': |
||
118 | echo PMF_Configuration::sortingOptions($faqConfig->get($key)); |
||
119 | break; |
||
120 | |||
121 | case 'records.sortby': |
||
122 | printf('<option value="DESC"%s>%s</option>', |
||
123 | ('DESC' == $faqConfig->get($key)) ? ' selected' : '', |
||
124 | $PMF_LANG['ad_conf_desc']); |
||
125 | printf('<option value="ASC"%s>%s</option>', |
||
126 | ('ASC' == $faqConfig->get($key)) ? ' selected' : '', |
||
127 | $PMF_LANG['ad_conf_asc']); |
||
128 | break; |
||
129 | |||
130 | case 'security.permLevel': |
||
131 | echo PMF_Perm::permOptions($faqConfig->get($key)); |
||
132 | break; |
||
133 | |||
134 | case 'main.templateSet': |
||
135 | $faqSystem = new PMF_System(); |
||
136 | $templates = $faqSystem->getAvailableTemplates(); |
||
137 | |||
138 | foreach ($templates as $template => $selected) { |
||
139 | printf ("<option%s>%s</option>", |
||
140 | ($selected === true ? ' selected' : ''), |
||
141 | $template |
||
142 | ); |
||
143 | } |
||
144 | break; |
||
145 | |||
146 | case "records.attachmentsStorageType": |
||
147 | foreach($PMF_LANG['att_storage_type'] as $i => $item) { |
||
148 | $selected = $faqConfig->get($key) == $i |
||
149 | ? ' selected' |
||
150 | : ''; |
||
151 | printf('<option value="%d"%s>%s</option>', |
||
152 | $i, $selected, $item); |
||
153 | } |
||
154 | break; |
||
155 | |||
156 | case "records.orderingPopularFaqs": |
||
157 | printf('<option value="visits"%s>%s</option>', |
||
158 | ('visits' == $faqConfig->get($key)) ? ' selected' : '', |
||
159 | $PMF_LANG['records.orderingPopularFaqs.visits']); |
||
160 | printf('<option value="voting"%s>%s</option>', |
||
161 | ('voting' == $faqConfig->get($key)) ? ' selected' : '', |
||
162 | $PMF_LANG['records.orderingPopularFaqs.voting']); |
||
163 | break; |
||
164 | |||
165 | case "search.relevance": |
||
166 | printf('<option value="thema,content,keywords"%s>%s</option>', |
||
167 | ('thema,content,keywords' == $faqConfig->get($key)) ? ' selected' : '', |
||
168 | $PMF_LANG['search.relevance.thema-content-keywords']); |
||
169 | printf('<option value="thema,keywords,content"%s>%s</option>', |
||
170 | ('thema,keywords,content' == $faqConfig->get($key)) ? ' selected' : '', |
||
171 | $PMF_LANG['search.relevance.thema-keywords-content']); |
||
172 | printf('<option value="content,thema,keywords"%s>%s</option>', |
||
173 | ('content,thema,keywords' == $faqConfig->get($key)) ? ' selected' : '', |
||
174 | $PMF_LANG['search.relevance.content-thema-keywords']); |
||
175 | printf('<option value="content,keywords,thema"%s>%s</option>', |
||
176 | ('content,keywords,thema' == $faqConfig->get($key)) ? ' selected' : '', |
||
177 | $PMF_LANG['search.relevance.content-keywords-thema']); |
||
178 | printf('<option value="keywords,content,thema"%s>%s</option>', |
||
179 | ('keywords,content,thema' == $faqConfig->get($key)) ? ' selected' : '', |
||
180 | $PMF_LANG['search.relevance.keywords-content-thema']); |
||
181 | printf('<option value="keywords,thema,content"%s>%s</option>', |
||
182 | ('keywords,thema,content' == $faqConfig->get($key)) ? ' selected' : '', |
||
183 | $PMF_LANG['search.relevance.keywords-thema-content']); |
||
184 | break; |
||
185 | } |
||
186 | |||
187 | echo "</select>\n</div>\n"; |
||
188 | break; |
||
189 | |||
190 | case 'checkbox': |
||
191 | printf( |
||
192 | '<div class="checkbox"><input type="checkbox" name="edit[%s]" value="true"', |
||
193 | $key |
||
194 | ); |
||
195 | if ($faqConfig->get($key)) { |
||
196 | echo ' checked'; |
||
197 | } |
||
198 | if ('security.ldapSupport' === $key && !extension_loaded('ldap')) { |
||
199 | echo ' disabled'; |
||
200 | } |
||
201 | if ('security.useSslOnly' === $key && empty($_SERVER['HTTPS'])) { |
||
202 | echo ' disabled'; |
||
203 | } |
||
204 | if ('security.ssoSupport' === $key && empty($_SERVER['REMOTE_USER'])) { |
||
205 | echo ' disabled'; |
||
206 | } |
||
207 | echo ">\n</div></div>\n"; |
||
208 | break; |
||
209 | |||
210 | case 'print': |
||
211 | printf( |
||
212 | '<input type="text" readonly name="edit[%s]" class="form-control" value="%s"></div>', |
||
213 | $key, |
||
214 | str_replace('"', '"', $faqConfig->get($key)), |
||
215 | $faqConfig->get($key) |
||
216 | ); |
||
217 | break; |
||
218 | } |
||
219 | } |
||
220 | |||
279 |