| Conditions | 6 |
| Paths | 10 |
| Total Lines | 61 |
| Code Lines | 22 |
| 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 |
||
| 78 | function elk_main() |
||
| 79 | { |
||
| 80 | global $modSettings, $context; |
||
| 81 | |||
| 82 | // What shall we do? |
||
| 83 | $dispatcher = new ElkArte\SiteDispatcher( HttpReq::instance()); |
||
| 84 | |||
| 85 | if ($dispatcher->needSecurity()) |
||
| 86 | { |
||
| 87 | // We should set our security headers now. |
||
| 88 | frameOptionsHeader(); |
||
| 89 | securityOptionsHeader(); |
||
| 90 | |||
| 91 | // Load the user's cookie (or set as guest) and load their settings. |
||
| 92 | User::load(true); |
||
| 93 | $dispatcher->setUser(User::$info); |
||
| 94 | |||
| 95 | // Load the current board's information. |
||
| 96 | loadBoard(); |
||
| 97 | |||
| 98 | // Load the current user's permissions. |
||
| 99 | loadPermissions(); |
||
| 100 | |||
| 101 | // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.) |
||
| 102 | if ($dispatcher->needTheme()) |
||
| 103 | { |
||
| 104 | // Do our BadBehavior checking before we go any further |
||
| 105 | if (runBadBehavior()) |
||
| 106 | { |
||
| 107 | // Not much to say, 403 and gone |
||
| 108 | sleep(10); |
||
| 109 | \ElkArte\Errors\Errors::instance()->display_403_error(true); |
||
| 110 | } |
||
| 111 | |||
| 112 | new ElkArte\Themes\ThemeLoader(); |
||
| 113 | |||
| 114 | // The parser is not an object just yet |
||
| 115 | loadBBCParsers(); |
||
| 116 | } |
||
| 117 | |||
| 118 | // Check if the user should be disallowed access. |
||
| 119 | is_not_banned(); |
||
| 120 | |||
| 121 | // Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc. |
||
| 122 | if ($dispatcher->trackStats()) |
||
| 123 | { |
||
| 124 | // I see you! |
||
| 125 | writeLog(); |
||
| 126 | |||
| 127 | // Track forum statistics and hits...? |
||
| 128 | if (!empty($modSettings['hitStats'])) |
||
| 129 | { |
||
| 130 | trackStats(['hits' => '+']); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | // Show where we came from, and go |
||
| 135 | $context['site_action'] = $dispatcher->site_action(); |
||
| 136 | } |
||
| 137 | |||
| 138 | $dispatcher->dispatch(); |
||
| 139 | } |
||
| 140 |
If you suppress an error, we recommend checking for the error condition explicitly: