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