Conditions | 35 |
Paths | 313 |
Total Lines | 234 |
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 |
||
160 | function smf_main() |
||
161 | { |
||
162 | global $modSettings, $settings, $user_info, $board, $topic; |
||
163 | global $board_info, $maintenance, $sourcedir; |
||
164 | |||
165 | // Special case: session keep-alive, output a transparent pixel. |
||
166 | if (isset($_GET['action']) && $_GET['action'] == 'keepalive') |
||
167 | { |
||
168 | header('content-type: image/gif'); |
||
169 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
||
170 | } |
||
171 | |||
172 | // We should set our security headers now. |
||
173 | frameOptionsHeader(); |
||
174 | |||
175 | // Load the user's cookie (or set as guest) and load their settings. |
||
176 | loadUserSettings(); |
||
177 | |||
178 | // Load the current board's information. |
||
179 | loadBoard(); |
||
180 | |||
181 | // Load the current user's permissions. |
||
182 | loadPermissions(); |
||
183 | |||
184 | // Attachments don't require the entire theme to be loaded. |
||
185 | if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') |
||
186 | detectBrowser(); |
||
187 | // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.) |
||
188 | else |
||
189 | loadTheme(); |
||
190 | |||
191 | // Check if the user should be disallowed access. |
||
192 | is_not_banned(); |
||
193 | |||
194 | // If we are in a topic and don't have permission to approve it then duck out now. |
||
195 | if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) |
||
196 | fatal_lang_error('not_a_topic', false); |
||
197 | |||
198 | $no_stat_actions = array('clock', 'dlattach', 'findmember', 'jsoption', 'likes', 'loadeditorlocale', 'modifycat', 'requestmembers', 'smstats', 'suggest', 'about:unknown', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile'); |
||
199 | call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions)); |
||
200 | // Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc. |
||
201 | if (empty($_REQUEST['action']) || !in_array($_REQUEST['action'], $no_stat_actions)) |
||
202 | { |
||
203 | // Log this user as online. |
||
204 | writeLog(); |
||
205 | |||
206 | // Track forum statistics and hits...? |
||
207 | if (!empty($modSettings['hitStats'])) |
||
208 | trackStats(array('hits' => '+')); |
||
209 | } |
||
210 | unset($no_stat_actions); |
||
211 | |||
212 | // Make sure that our scheduled tasks have been running as intended |
||
213 | check_cron(); |
||
214 | |||
215 | // Is the forum in maintenance mode? (doesn't apply to administrators.) |
||
216 | if (!empty($maintenance) && !allowedTo('admin_forum')) |
||
217 | { |
||
218 | // You can only login.... otherwise, you're getting the "maintenance mode" display. |
||
219 | if (isset($_REQUEST['action']) && (in_array($_REQUEST['action'], array('login2', 'logintfa', 'logout')))) |
||
220 | { |
||
221 | require_once($sourcedir . '/LogInOut.php'); |
||
222 | return ($_REQUEST['action'] == 'login2' ? 'Login2' : ($_REQUEST['action'] == 'logintfa' ? 'LoginTFA' : 'Logout')); |
||
223 | } |
||
224 | // Don't even try it, sonny. |
||
225 | else |
||
226 | return 'InMaintenance'; |
||
227 | } |
||
228 | // If guest access is off, a guest can only do one of the very few following actions. |
||
229 | elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) |
||
230 | return 'KickGuest'; |
||
231 | elseif (empty($_REQUEST['action'])) |
||
232 | { |
||
233 | // Action and board are both empty... BoardIndex! Unless someone else wants to do something different. |
||
234 | if (empty($board) && empty($topic)) |
||
235 | { |
||
236 | if (!empty($modSettings['integrate_default_action'])) |
||
237 | { |
||
238 | $defaultAction = explode(',', $modSettings['integrate_default_action']); |
||
239 | |||
240 | // Sorry, only one default action is needed. |
||
241 | $defaultAction = $defaultAction[0]; |
||
242 | |||
243 | $call = call_helper($defaultAction, true); |
||
244 | |||
245 | if (!empty($call)) |
||
246 | return $call; |
||
247 | } |
||
248 | |||
249 | // No default action huh? then go to our good old BoardIndex. |
||
250 | else |
||
251 | { |
||
252 | require_once($sourcedir . '/BoardIndex.php'); |
||
253 | |||
254 | return 'BoardIndex'; |
||
255 | } |
||
256 | } |
||
257 | |||
258 | // Topic is empty, and action is empty.... MessageIndex! |
||
259 | elseif (empty($topic)) |
||
260 | { |
||
261 | require_once($sourcedir . '/MessageIndex.php'); |
||
262 | return 'MessageIndex'; |
||
263 | } |
||
264 | |||
265 | // Board is not empty... topic is not empty... action is empty.. Display! |
||
266 | else |
||
267 | { |
||
268 | require_once($sourcedir . '/Display.php'); |
||
269 | return 'Display'; |
||
270 | } |
||
271 | } |
||
272 | |||
273 | // Here's the monstrous $_REQUEST['action'] array - $_REQUEST['action'] => array($file, $function). |
||
274 | $actionArray = array( |
||
275 | 'activate' => array('Register.php', 'Activate'), |
||
276 | 'admin' => array('Admin.php', 'AdminMain'), |
||
277 | 'announce' => array('Post.php', 'AnnounceTopic'), |
||
278 | 'attachapprove' => array('ManageAttachments.php', 'ApproveAttach'), |
||
279 | 'buddy' => array('Subs-Members.php', 'BuddyListToggle'), |
||
280 | 'calendar' => array('Calendar.php', 'CalendarMain'), |
||
281 | 'clock' => array('Calendar.php', 'clock'), |
||
282 | 'coppa' => array('Register.php', 'CoppaForm'), |
||
283 | 'credits' => array('Who.php', 'Credits'), |
||
284 | 'deletemsg' => array('RemoveTopic.php', 'DeleteMessage'), |
||
285 | 'dlattach' => array('ShowAttachments.php', 'showAttachment'), |
||
286 | 'editpoll' => array('Poll.php', 'EditPoll'), |
||
287 | 'editpoll2' => array('Poll.php', 'EditPoll2'), |
||
288 | 'findmember' => array('Subs-Auth.php', 'JSMembers'), |
||
289 | 'groups' => array('Groups.php', 'Groups'), |
||
290 | 'help' => array('Help.php', 'ShowHelp'), |
||
291 | 'helpadmin' => array('Help.php', 'ShowAdminHelp'), |
||
292 | 'jsmodify' => array('Post.php', 'JavaScriptModify'), |
||
293 | 'jsoption' => array('Themes.php', 'SetJavaScript'), |
||
294 | 'likes' => array('Likes.php', 'Likes::call#'), |
||
295 | 'loadeditorlocale' => array('Subs-Editor.php', 'loadLocale'), |
||
296 | 'lock' => array('Topic.php', 'LockTopic'), |
||
297 | 'lockvoting' => array('Poll.php', 'LockVoting'), |
||
298 | 'login' => array('LogInOut.php', 'Login'), |
||
299 | 'login2' => array('LogInOut.php', 'Login2'), |
||
300 | 'logintfa' => array('LogInOut.php', 'LoginTFA'), |
||
301 | 'logout' => array('LogInOut.php', 'Logout'), |
||
302 | 'markasread' => array('Subs-Boards.php', 'MarkRead'), |
||
303 | 'mergetopics' => array('SplitTopics.php', 'MergeTopics'), |
||
304 | 'mlist' => array('Memberlist.php', 'Memberlist'), |
||
305 | 'moderate' => array('ModerationCenter.php', 'ModerationMain'), |
||
306 | 'modifycat' => array('ManageBoards.php', 'ModifyCat'), |
||
307 | 'movetopic' => array('MoveTopic.php', 'MoveTopic'), |
||
308 | 'movetopic2' => array('MoveTopic.php', 'MoveTopic2'), |
||
309 | 'notify' => array('Notify.php', 'Notify'), |
||
310 | 'notifyboard' => array('Notify.php', 'BoardNotify'), |
||
311 | 'notifytopic' => array('Notify.php', 'TopicNotify'), |
||
312 | 'pm' => array('PersonalMessage.php', 'MessageMain'), |
||
313 | 'post' => array('Post.php', 'Post'), |
||
314 | 'post2' => array('Post.php', 'Post2'), |
||
315 | 'printpage' => array('Printpage.php', 'PrintTopic'), |
||
316 | 'profile' => array('Profile.php', 'ModifyProfile'), |
||
317 | 'quotefast' => array('Post.php', 'QuoteFast'), |
||
318 | 'quickmod' => array('MessageIndex.php', 'QuickModeration'), |
||
319 | 'quickmod2' => array('Display.php', 'QuickInTopicModeration'), |
||
320 | 'recent' => array('Recent.php', 'RecentPosts'), |
||
321 | 'reminder' => array('Reminder.php', 'RemindMe'), |
||
322 | 'removepoll' => array('Poll.php', 'RemovePoll'), |
||
323 | 'removetopic2' => array('RemoveTopic.php', 'RemoveTopic2'), |
||
324 | 'reporttm' => array('ReportToMod.php', 'ReportToModerator'), |
||
325 | 'requestmembers' => array('Subs-Auth.php', 'RequestMembers'), |
||
326 | 'restoretopic' => array('RemoveTopic.php', 'RestoreTopic'), |
||
327 | 'search' => array('Search.php', 'PlushSearch1'), |
||
328 | 'search2' => array('Search.php', 'PlushSearch2'), |
||
329 | 'sendactivation' => array('Register.php', 'SendActivation'), |
||
330 | 'signup' => array('Register.php', 'Register'), |
||
331 | 'signup2' => array('Register.php', 'Register2'), |
||
332 | 'smstats' => array('Stats.php', 'SMStats'), |
||
333 | 'suggest' => array('Subs-Editor.php', 'AutoSuggestHandler'), |
||
334 | 'spellcheck' => array('Subs-Post.php', 'SpellCheck'), |
||
335 | 'splittopics' => array('SplitTopics.php', 'SplitTopics'), |
||
336 | 'stats' => array('Stats.php', 'DisplayStats'), |
||
337 | 'sticky' => array('Topic.php', 'Sticky'), |
||
338 | 'theme' => array('Themes.php', 'ThemesMain'), |
||
339 | 'trackip' => array('Profile-View.php', 'trackIP'), |
||
340 | 'about:unknown' => array('Likes.php', 'BookOfUnknown'), |
||
341 | 'unread' => array('Recent.php', 'UnreadTopics'), |
||
342 | 'unreadreplies' => array('Recent.php', 'UnreadTopics'), |
||
343 | 'uploadAttach' => array('Attachments.php', 'Attachments::call#'), |
||
344 | 'verificationcode' => array('Register.php', 'VerificationCode'), |
||
345 | 'viewprofile' => array('Profile.php', 'ModifyProfile'), |
||
346 | 'vote' => array('Poll.php', 'Vote'), |
||
347 | 'viewquery' => array('ViewQuery.php', 'ViewQuery'), |
||
348 | 'viewsmfile' => array('Admin.php', 'DisplayAdminFile'), |
||
349 | 'who' => array('Who.php', 'Who'), |
||
350 | '.xml' => array('News.php', 'ShowXmlFeed'), |
||
351 | 'xmlhttp' => array('Xml.php', 'XMLhttpMain'), |
||
352 | ); |
||
353 | |||
354 | // Allow modifying $actionArray easily. |
||
355 | call_integration_hook('integrate_actions', array(&$actionArray)); |
||
356 | |||
357 | // Get the function and file to include - if it's not there, do the board index. |
||
358 | if (!isset($_REQUEST['action']) || !isset($actionArray[$_REQUEST['action']])) |
||
359 | { |
||
360 | // Catch the action with the theme? |
||
361 | if (!empty($settings['catch_action'])) |
||
362 | { |
||
363 | require_once($sourcedir . '/Themes.php'); |
||
364 | return 'WrapAction'; |
||
365 | } |
||
366 | |||
367 | if (!empty($modSettings['integrate_fallback_action'])) |
||
368 | { |
||
369 | $fallbackAction = explode(',', $modSettings['integrate_fallback_action']); |
||
370 | |||
371 | // Sorry, only one fallback action is needed. |
||
372 | $fallbackAction = $fallbackAction[0]; |
||
373 | |||
374 | $call = call_helper($fallbackAction, true); |
||
375 | |||
376 | if (!empty($call)) |
||
377 | return $call; |
||
378 | } |
||
379 | |||
380 | // No fallback action, huh? |
||
381 | else |
||
382 | { |
||
383 | fatal_lang_error('not_found', false, array(), 404); |
||
384 | } |
||
385 | } |
||
386 | |||
387 | // Otherwise, it was set - so let's go to that action. |
||
388 | if (!empty($actionArray[$_REQUEST['action']][0])) |
||
389 | require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]); |
||
390 | |||
391 | // Do the right thing. |
||
392 | return call_helper($actionArray[$_REQUEST['action']][1], true); |
||
393 | } |
||
394 | |||
395 | ?> |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]
orarray<String>
.