forum::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

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