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