| Conditions | 5 |
| Paths | 7 |
| Total Lines | 62 |
| 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 |
||
| 75 | function elk_main() |
||
| 76 | { |
||
| 77 | global $modSettings, $context; |
||
| 78 | |||
| 79 | // A safer way to work with our form globals |
||
| 80 | // @todo Use a DIC |
||
| 81 | $_req = HttpReq::instance(); |
||
| 82 | |||
| 83 | // What shall we do? |
||
| 84 | $dispatcher = new Site_Dispatcher($_req); |
||
| 85 | |||
| 86 | if ($dispatcher->needSecurity()) |
||
| 87 | { |
||
| 88 | // We should set our security headers now. |
||
| 89 | frameOptionsHeader(); |
||
| 90 | securityOptionsHeader(); |
||
| 91 | |||
| 92 | // Load the user's cookie (or set as guest) and load their settings. |
||
| 93 | loadUserSettings(); |
||
| 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 | loadTheme(); |
||
| 105 | |||
| 106 | // Load BadBehavior before we go much further |
||
| 107 | loadBadBehavior(); |
||
| 108 | |||
| 109 | // The parser is not a DIC just yet |
||
| 110 | loadBBCParsers(); |
||
| 111 | } |
||
| 112 | // Otherwise don't require the entire theme to be loaded. |
||
| 113 | else |
||
| 114 | { |
||
| 115 | detectBrowser(); |
||
| 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 | trackStats(array('hits' => '+')); |
||
| 130 | } |
||
| 131 | |||
| 132 | // Show where we came from, and go |
||
| 133 | $context['site_action'] = $dispatcher->site_action(); |
||
| 134 | } |
||
| 135 | |||
| 136 | $dispatcher->dispatch(); |
||
| 137 | } |
If you suppress an error, we recommend checking for the error condition explicitly: