| Conditions | 15 |
| Paths | 33 |
| Total Lines | 94 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 13 | ||
| Bugs | 0 | Features | 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 |
||
| 25 | public function ideas_list($sort) |
||
| 26 | { |
||
| 27 | if (!$this->is_available()) |
||
| 28 | { |
||
| 29 | throw new http_exception(404, 'IDEAS_NOT_AVAILABLE'); |
||
| 30 | } |
||
| 31 | |||
| 32 | // Overwrite the $sort parameter if the url contains a sort query. |
||
| 33 | // This is needed with the sort by options form at the footer of the list. |
||
| 34 | $sort = $this->request->is_set('sort') ? $this->request->variable('sort', ideas::SORT_NEW) : $sort; |
||
| 35 | |||
| 36 | // Get additional query values the url may contain |
||
| 37 | $sort_direction = $this->request->variable('sd', 'd'); |
||
| 38 | $status = $this->request->variable('status', 0); |
||
| 39 | $start = $this->request->variable('start', 0); |
||
| 40 | |||
| 41 | // Store original query params for use in breadcrumbs & pagination |
||
| 42 | $u_sort = $sort; |
||
| 43 | $u_status = $status; |
||
| 44 | $u_sort_direction = $sort_direction; |
||
| 45 | |||
| 46 | // convert the sort direction to ASC or DESC |
||
| 47 | $sort_direction = ($sort_direction === 'd') ? 'DESC' : 'ASC'; |
||
| 48 | |||
| 49 | // If sort by "new" we really use date |
||
| 50 | if ($sort === ideas::SORT_NEW) |
||
| 51 | { |
||
| 52 | $sort = ideas::SORT_DATE; |
||
| 53 | } |
||
| 54 | |||
| 55 | // Set the name for displaying in the template |
||
| 56 | $status_name = 'LIST_' . strtoupper($status > 0 ? array_search($status, ideas::$statuses) : $sort); |
||
|
|
|||
| 57 | $status_name = $this->language->is_set($status_name) ? $this->language->lang($status_name) : ''; |
||
| 58 | |||
| 59 | // For special case where we want to request ALL ideas, |
||
| 60 | // including the statuses normally hidden from lists. |
||
| 61 | if ($status === -1) |
||
| 62 | { |
||
| 63 | $status = ideas::$statuses; |
||
| 64 | $status_name = $status_name ?: $this->language->lang('ALL_IDEAS'); |
||
| 65 | } |
||
| 66 | |||
| 67 | // Generate ideas |
||
| 68 | $ideas = $this->ideas->get_ideas($this->config['posts_per_page'], $sort, $sort_direction, $status, $start); |
||
| 69 | $this->assign_template_block_vars('ideas', $ideas); |
||
| 70 | |||
| 71 | // Build list page template output |
||
| 72 | $this->template->assign_vars(array( |
||
| 73 | 'U_LIST_ACTION' => $this->helper->route('phpbb_ideas_list_controller'), |
||
| 74 | 'U_POST_ACTION' => $this->helper->route('phpbb_ideas_post_controller'), |
||
| 75 | 'IDEAS_COUNT' => $this->ideas->get_idea_count(), |
||
| 76 | 'STATUS_NAME' => $status_name ?: $this->language->lang('OPEN_IDEAS'), |
||
| 77 | 'STATUS_ARY' => ideas::$statuses, |
||
| 78 | 'STATUS' => $u_status, |
||
| 79 | 'SORT_ARY' => array(ideas::SORT_AUTHOR, ideas::SORT_DATE, ideas::SORT_SCORE, ideas::SORT_TITLE, ideas::SORT_TOP, ideas::SORT_VOTES), |
||
| 80 | 'SORT' => $sort, |
||
| 81 | 'SORT_DIRECTION' => $sort_direction, |
||
| 82 | 'U_MCP' => ($this->auth->acl_get('m_', $this->config['ideas_forum_id'])) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", "f={$this->config['ideas_forum_id']}&i=main&mode=forum_view", true, $this->user->session_id) : '', |
||
| 83 | |||
| 84 | )); |
||
| 85 | |||
| 86 | // Recreate the url parameters for the current list |
||
| 87 | $params = array( |
||
| 88 | 'sort' => $u_sort ?: null, |
||
| 89 | 'status' => $u_status ?: null, |
||
| 90 | 'sd' => $u_sort_direction ?: null, |
||
| 91 | ); |
||
| 92 | |||
| 93 | // Assign breadcrumb template vars |
||
| 94 | $this->template->assign_block_vars_array('navlinks', array( |
||
| 95 | array( |
||
| 96 | 'U_VIEW_FORUM' => $this->helper->route('phpbb_ideas_index_controller'), |
||
| 97 | 'FORUM_NAME' => $this->language->lang('IDEAS'), |
||
| 98 | ), |
||
| 99 | array( |
||
| 100 | 'U_VIEW_FORUM' => $this->helper->route('phpbb_ideas_list_controller', $params), |
||
| 101 | 'FORUM_NAME' => $status_name ?: $this->language->lang('OPEN_IDEAS'), |
||
| 102 | ), |
||
| 103 | )); |
||
| 104 | |||
| 105 | // Generate template pagination |
||
| 106 | $this->pagination->generate_template_pagination( |
||
| 107 | $this->helper->route('phpbb_ideas_list_controller', $params), |
||
| 108 | 'pagination', |
||
| 109 | 'start', |
||
| 110 | $this->ideas->get_idea_count(), |
||
| 111 | $this->config['posts_per_page'], |
||
| 112 | $start |
||
| 113 | ); |
||
| 114 | |||
| 115 | // Display common ideas template vars |
||
| 116 | $this->display_common_vars(); |
||
| 117 | |||
| 118 | return $this->helper->render('list_body.html', $this->language->lang('IDEA_LIST')); |
||
| 119 | } |
||
| 121 |