Passed
Pull Request — master (#132)
by Matt
01:19
created

base::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 15
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 11

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\auth\auth;
14
use phpbb\config\config;
15
use phpbb\controller\helper;
16
use phpbb\ideas\ext;
17
use phpbb\ideas\factory\linkhelper;
18
use phpbb\language\language;
19
use phpbb\pagination;
20
use phpbb\request\request;
21
use phpbb\template\template;
22
use phpbb\user;
23
24
abstract class base
25
{
26
	/** @var auth */
27
	protected $auth;
28
29
	/* @var config */
30
	protected $config;
31
32
	/* @var helper */
33
	protected $helper;
34
35
	/* @var \phpbb\ideas\factory\ideas|\phpbb\ideas\factory\idea */
36
	protected $ideas;
37
38
	/** @var language  */
39
	protected $language;
40
41
	/* @var linkhelper */
42
	protected $link_helper;
43
44
	/** @var pagination */
45
	protected $pagination;
46
47
	/* @var request */
48
	protected $request;
49
50
	/* @var template */
51
	protected $template;
52
53
	/* @var user */
54
	protected $user;
55
56
	/** @var string */
57
	protected $root_path;
58
59
	/** @var string */
60
	protected $php_ext;
61
62
	/**
63
	 * @param auth       $auth
64
	 * @param config     $config
65
	 * @param helper     $helper
66
	 * @param language   $language
67
	 * @param linkhelper $link_helper
68
	 * @param pagination $pagination
69
	 * @param request    $request
70
	 * @param template   $template
71
	 * @param user       $user
72
	 * @param string     $root_path
73
	 * @param string     $php_ext
74
	 */
75
	public function __construct(auth $auth, config $config, helper $helper, language $language, linkhelper $link_helper, pagination $pagination, request $request, template $template, user $user, $root_path, $php_ext)
76
	{
77
		$this->auth = $auth;
78
		$this->config = $config;
79
		$this->helper = $helper;
80
		$this->language = $language;
81
		$this->link_helper = $link_helper;
82
		$this->pagination = $pagination;
83
		$this->request = $request;
84
		$this->template = $template;
85
		$this->user = $user;
86
		$this->root_path = $root_path;
87
		$this->php_ext = $php_ext;
88
89
		$this->language->add_lang('common', 'phpbb/ideas');
90
	}
91
92
	/**
93
	 * Set the Ideas entity
94
	 *
95
	 * @param \phpbb\ideas\factory\ideas|\phpbb\ideas\factory\idea $entity
96
	 */
97
	public function get_entity($entity)
98
	{
99
		$this->ideas = $entity;
100
	}
101
102
	/**
103
	 * Check if Ideas is properly configured after installation
104
	 * Ideas is available only after forum settings have been set in ACP
105
	 *
106
	 * @return bool Depending on whether or not the extension is properly configured
107
	 */
108
	public function is_available()
109
	{
110
		return (bool) $this->config['ideas_forum_id'];
111
	}
112
113
	/**
114
	 * Assign idea lists template variables
115
	 *
116
	 * @param string $block The template block var name
117
	 * @param array  $rows  The Idea row data
118
	 *
119
	 * @return void
120
	 */
121
	protected function assign_template_block_vars($block, $rows)
122
	{
123
		foreach ($rows as $row)
124
		{
125
			$this->template->assign_block_vars($block, array(
126
				'ID'         => $row['idea_id'], // (not currently implemented)
127
				'LINK'       => $this->link_helper->get_idea_link($row['idea_id']),
128
				'TITLE'      => $row['idea_title'],
129
				'AUTHOR'     => $this->link_helper->get_user_link($row['idea_author']),
130
				'DATE'       => $this->user->format_date($row['idea_date']),
131
				'READ'       => $row['read'],
132
				'VOTES_UP'   => $row['idea_votes_up'],
133
				'VOTES_DOWN' => $row['idea_votes_down'],
134
				'USER_VOTED' => $row['u_voted'],
135
				'POINTS'     => $row['idea_votes_up'] - $row['idea_votes_down'], // (not currently implemented)
136
				'STATUS'     => $row['idea_status'], // for status icons (not currently implemented)
137
				'LOCKED'     => $row['topic_status'] == ITEM_LOCKED,
138
				'U_UNAPPROVED_IDEA'	=> (($row['topic_visibility'] == ITEM_UNAPPROVED || $row['topic_visibility'] == ITEM_REAPPROVE) && $this->auth->acl_get('m_approve', $this->config['ideas_forum_id'])) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=queue&amp;mode=approve_details&amp;t=' . $row['topic_id'], true, $this->user->session_id) : '',
139
			));
140
		}
141
	}
142
143
	/**
144
	 * Assign common template variables for Ideas pages
145
	 *
146
	 * @return void
147
	 */
148
	protected function display_common_vars()
149
	{
150
		$this->template->assign_vars([
151
			'S_DISPLAY_SEARCHBOX'	=> (bool) $this->auth->acl_get('u_search') && $this->auth->acl_get('f_search', $this->config['ideas_forum_id']) && $this->config['load_search'],
152
			'S_SEARCHBOX_ACTION'	=> append_sid("{$this->root_path}search.{$this->php_ext}"),
153
			'S_SEARCH_IDEAS_HIDDEN_FIELDS'	=> build_hidden_fields(['fid' => [$this->config['ideas_forum_id']]]),
154
155
			'U_SEARCH_MY_IDEAS' 	=> $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_MYIDEAS, 'status' => '-1']),
156
		]);
157
	}
158
}
159