| Conditions | 5 |
| Paths | 7 |
| Total Lines | 65 |
| Code Lines | 23 |
| 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 |
||
| 85 | function elk_main() |
||
| 86 | { |
||
| 87 | global $modSettings, $context; |
||
| 88 | |||
| 89 | // A safer way to work with our form globals |
||
| 90 | // @todo Use dependency injection |
||
| 91 | $_req = HttpReq::instance(); |
||
| 92 | |||
| 93 | // What shall we do? |
||
| 94 | $dispatcher = new ElkArte\SiteDispatcher($_req); |
||
| 95 | |||
| 96 | if ($dispatcher->needSecurity()) |
||
| 97 | { |
||
| 98 | // We should set our security headers now. |
||
| 99 | frameOptionsHeader(); |
||
| 100 | securityOptionsHeader(); |
||
| 101 | |||
| 102 | // Load the user's cookie (or set as guest) and load their settings. |
||
| 103 | User::load(true); |
||
| 104 | $dispatcher->setUser(User::$info); |
||
| 105 | |||
| 106 | // Load the current board's information. |
||
| 107 | loadBoard(); |
||
| 108 | |||
| 109 | // Load the current user's permissions. |
||
| 110 | loadPermissions(); |
||
| 111 | |||
| 112 | // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.) |
||
| 113 | if ($dispatcher->needTheme()) |
||
| 114 | { |
||
| 115 | new ElkArte\Themes\ThemeLoader(); |
||
| 116 | |||
| 117 | // Load BadBehavior before we go much further |
||
| 118 | loadBadBehavior(); |
||
| 119 | |||
| 120 | // The parser is not an object just yet |
||
| 121 | loadBBCParsers(); |
||
| 122 | } |
||
| 123 | // Otherwise don't require the entire theme to be loaded. |
||
| 124 | else |
||
| 125 | { |
||
| 126 | detectBrowser(); |
||
| 127 | } |
||
| 128 | |||
| 129 | // Check if the user should be disallowed access. |
||
| 130 | is_not_banned(); |
||
| 131 | |||
| 132 | // Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc. |
||
| 133 | if ($dispatcher->trackStats()) |
||
| 134 | { |
||
| 135 | // I see you! |
||
| 136 | writeLog(); |
||
| 137 | |||
| 138 | // Track forum statistics and hits...? |
||
| 139 | if (!empty($modSettings['hitStats'])) |
||
| 140 | { |
||
| 141 | trackStats(array('hits' => '+')); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | // Show where we came from, and go |
||
| 146 | $context['site_action'] = $dispatcher->site_action(); |
||
| 147 | } |
||
| 148 | |||
| 149 | $dispatcher->dispatch(); |
||
| 150 | } |
||
| 151 |
If you suppress an error, we recommend checking for the error condition explicitly: