Passed
Push — develop-webpack ( 4e7aad...7a1ea0 )
by Daniel
04:14
created

forum::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 8
dl 0
loc 10
rs 10
c 0
b 0
f 0

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
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\controller;
11
12
class forum
13
{
14
	/** @var \phpbb\auth\auth */
15
	protected $auth;
16
17
	/** @var \phpbb\config\config */
18
	protected $config;
19
20
	/** @var \phpbb\controller\helper */
21
	protected $helper;
22
23
	/** @var \phpbb\template\template */
24
	protected $template;
25
26
	/** @var \phpbb\language\language */
27
	protected $translator;
28
29
	/** @var \phpbb\user */
30
	protected $user;
31
32
	/** @var string phpBB root path */
33
	protected $phpbb_root_path;
34
35
	/** @var string phpEx */
36
	protected $php_ext;
37
38
	/**
39
	 * Constructor
40
	 *
41
	 * @param \phpbb\auth\auth				$auth			Auth object
42
	 * @param \phpbb\config\config			$config			Config object
43
	 * @param \phpbb\controller\helper		$helper			Controller Helper object
44
	 * @param \phpbb\template\template		$template		Template object
45
	 * @param \phpbb\language\language		$translator		Language object
46
	 * @param \phpbb\user					$user			User object
47
	 * @param string						$root_path		phpBB root path
48
	 * @param string						$php_ext		phpEx
49
	 */
50
	public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\language\language $translator, \phpbb\user $user, $root_path, $php_ext)
51
	{
52
		$this->auth = $auth;
53
		$this->config = $config;
54
		$this->helper = $helper;
55
		$this->template = $template;
56
		$this->translator = $translator;
57
		$this->user = $user;
58
		$this->phpbb_root_path = $root_path;
59
		$this->php_ext = $php_ext;
60
	}
61
62
	/**
63
	 * @return \Symfony\Component\HttpFoundation\Response
64
	 */
65
	public function handle()
66
	{
67
		/**
68
		 * This is ugly but the only way I could find
69
		 * to fix relative paths for forum images
70
		 */
71
		global $phpbb_root_path;
72
		$phpbb_root_path = generate_board_url() . '/';
73
74
		// @codeCoverageIgnoreStart
75
		if (!function_exists('display_forums'))
76
		{
77
			include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext);
78
		}
79
		// @codeCoverageIgnoreEnd
80
81
		display_forums('', $this->config['load_moderators']);
82
83
		$this->set_mcp_url();
84
		$this->set_mark_forums_url();
85
86
		// restore phpbb_root_path
87
		$phpbb_root_path = $this->phpbb_root_path;
88
89
		$this->template->assign_block_vars('navlinks', array(
90
			'FORUM_NAME'	=> $this->translator->lang('FORUM'),
91
			'U_VIEW_FORUM'	=> $this->helper->route('blitze_sitemaker_forum'),
92
		));
93
94
		return $this->helper->render('index_body.html', $this->translator->lang('FORUM_INDEX'));
95
	}
96
97
	/**
98
	 * @return void
99
	 */
100
	protected function set_mcp_url()
101
	{
102
		if ($this->auth->acl_get('m_') || $this->auth->acl_getf_global('m_'))
103
		{
104
			$this->template->assign_var('U_MCP', append_sid("{$this->phpbb_root_path}mcp.{$this->php_ext}", 'i=main&amp;mode=front', true, $this->user->session_id));
105
		}
106
	}
107
108
	/**
109
	 * @return void
110
	 */
111
	protected function set_mark_forums_url()
112
	{
113
		if ($this->user->data['is_registered'] || $this->config['load_anon_lastread'])
114
		{
115
			$this->template->assign_var('U_MARK_FORUMS', $this->helper->route('blitze_sitemaker_forum', array(
116
				'hash'		=> generate_link_hash('global'),
117
				'mark'		=> 'forums',
118
				'mark_time'	=> time(),
119
			)));
120
		}
121
	}
122
}
123