Completed
Branch master (b1a112)
by Matt
01:21
created

list_controller::ideas_list()   C

Complexity

Conditions 15
Paths 33

Size

Total Lines 94
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 13
Bugs 0 Features 0
Metric Value
eloc 50
c 13
b 0
f 0
dl 0
loc 94
rs 5.9166
cc 15
nc 33
nop 1

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
/**
3
 *
4
 * Ideas extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\ideas\controller;
12
13
use phpbb\exception\http_exception;
1 ignored issue
show
Bug introduced by
The type phpbb\exception\http_exception was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use phpbb\ideas\factory\ideas;
15
16
class list_controller extends base
17
{
18
	/**
19
	 * Controller for /list/{sort}
20
	 *
21
	 * @param $sort string The type of list to show (new|top|implemented)
22
	 * @throws http_exception
23
	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
1 ignored issue
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
	 */
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);
0 ignored issues
show
Bug introduced by
It seems like $status > 0 ? array_sear...deas::statuses) : $sort can also be of type false; however, parameter $string of strtoupper() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
		$status_name = 'LIST_' . strtoupper(/** @scrutinizer ignore-type */ $status > 0 ? array_search($status, ideas::$statuses) : $sort);
Loading history...
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']}&amp;i=main&amp;mode=forum_view", true, $this->user->session_id) : '',
1 ignored issue
show
Bug introduced by
The function append_sid was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

82
			'U_MCP' 			=> ($this->auth->acl_get('m_', $this->config['ideas_forum_id'])) ? /** @scrutinizer ignore-call */ append_sid("{$this->root_path}mcp.{$this->php_ext}", "f={$this->config['ideas_forum_id']}&amp;i=main&amp;mode=forum_view", true, $this->user->session_id) : '',
Loading history...
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
	}
120
}
121