| Conditions | 4 |
| Paths | 8 |
| Total Lines | 60 |
| Code Lines | 29 |
| 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 |
||
| 22 | public static function output($template, $data = [], $template_only = false) { |
||
| 23 | |||
| 24 | global $page_errors; |
||
| 25 | //////////////////////////////////////////////////////////// |
||
| 26 | // Find the user's country. Used by header, so a safe bit to do regardless. |
||
| 27 | if (preg_match('#^[A-Z]{2}$#i', get_http_var('country'))) { |
||
| 28 | $data['country'] = strtoupper(get_http_var('country')); |
||
| 29 | } else { |
||
| 30 | $data['country'] = Utility\Gaze::getCountryByIp($_SERVER["REMOTE_ADDR"]); |
||
| 31 | } |
||
| 32 | |||
| 33 | //////////////////////////////////////////////////////////// |
||
| 34 | // Get the page data |
||
| 35 | global $DATA, $this_page, $THEUSER; |
||
| 36 | |||
| 37 | $header = new Renderer\Header(); |
||
| 38 | $data = array_merge($header->data, $data); |
||
| 39 | |||
| 40 | $user = new Renderer\User(); |
||
| 41 | $data = array_merge($user->data, $data); |
||
| 42 | |||
| 43 | if (isset($page_errors)) { |
||
| 44 | $data['page_errors'] = $page_errors; |
||
| 45 | } |
||
| 46 | |||
| 47 | //////////////////////////////////////////////////////////// |
||
| 48 | // Search URL |
||
| 49 | |||
| 50 | $SEARCH = new Url('search'); |
||
| 51 | $SEARCH->reset(); |
||
| 52 | $data['search_url'] = $SEARCH->generate(); |
||
| 53 | |||
| 54 | //////////////////////////////////////////////////////////// |
||
| 55 | // Search URL |
||
| 56 | // Footer Links |
||
| 57 | |||
| 58 | $footer = new Renderer\Footer(); |
||
| 59 | $data['footer_links'] = $footer->data; |
||
| 60 | |||
| 61 | # banner text |
||
| 62 | $announcement_manager = new Model\AnnouncementManagement(); |
||
| 63 | $data['random_banner'] = $announcement_manager->get_random_valid_banner(); |
||
| 64 | $data = self::addCommonURLs($data); |
||
| 65 | |||
| 66 | //////////////////////////////////////////////////////////// |
||
| 67 | // Unpack the data we've been passed so it's available for use in the templates. |
||
| 68 | |||
| 69 | extract($data); |
||
| 70 | |||
| 71 | //////////////////////////////////////////////////////////// |
||
| 72 | // Require the templates and output |
||
| 73 | |||
| 74 | if ($template_only) { |
||
| 75 | require_once INCLUDESPATH . 'easyparliament/templates/html/' . $template . '.php'; |
||
| 76 | } else { |
||
| 77 | header('Content-Type: text/html; charset=utf-8'); |
||
| 78 | require_once INCLUDESPATH . 'easyparliament/templates/html/header.php'; |
||
| 79 | require_once INCLUDESPATH . 'easyparliament/templates/html/' . $template . '.php'; |
||
| 80 | require_once INCLUDESPATH . 'easyparliament/templates/html/footer.php'; |
||
| 81 | exit; |
||
|
|
|||
| 82 | } |
||
| 105 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.