portal::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 11
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 10

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\content\services\views\driver;
11
12
class portal extends base_view
13
{
14
	/** @var \phpbb\config\config */
15
	protected $config;
16
17
	/** @var \blitze\content\services\types */
18
	protected $content_types;
19
20
	/**
21
	 * Constructor
22
	 *
23
	 * @param \phpbb\event\dispatcher_interface					$phpbb_dispatcher		Event dispatcher object
24
	 * @param \phpbb\language\language							$language				Language Object
25
	 * @param \phpbb\pagination									$pagination				Pagination object
26
	 * @param \phpbb\template\template							$template				Template object
27
	 * @param \blitze\content\services\fields					$fields					Content fields object
28
	 * @param \blitze\sitemaker\services\forum\data				$forum					Forum Data object
29
	 * @param \blitze\content\services\helper					$helper					Content helper object
30
	 * @param \blitze\content\services\quickmod					$quickmod				Quick moderator tools
31
	 * @param \blitze\content\services\topic\blocks_factory		$topic_blocks_factory	Topic blocks factory object
32
	 * @param \phpbb\config\config								$config					Config object
33
	 * @param \blitze\content\services\types					$content_types			Content types object
34
	*/
35
	public function __construct(\phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\language\language $language, \phpbb\pagination $pagination, \phpbb\template\template $template, \blitze\content\services\fields $fields, \blitze\sitemaker\services\forum\data $forum, \blitze\content\services\helper $helper, \blitze\content\services\quickmod $quickmod, \blitze\content\services\topic\blocks_factory $topic_blocks_factory, \phpbb\config\config $config, \blitze\content\services\types $content_types)
0 ignored issues
show
Bug introduced by
The type blitze\sitemaker\services\forum\data 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...
36
	{
37
		parent::__construct($phpbb_dispatcher, $language, $pagination, $template, $fields, $forum, $helper, $quickmod, $topic_blocks_factory);
38
39
		$this->config = $config;
40
		$this->content_types = $content_types;
41
	}
42
43
	/**
44
	 * @inheritdoc
45
	 */
46
	public function get_name()
47
	{
48
		return 'portal';
49
	}
50
51
	/**
52
	 * @inheritdoc
53
	 */
54
	public function get_langname()
55
	{
56
		return 'CONTENT_DISPLAY_PORTAL';
57
	}
58
59
	/**
60
	 * @inheritdoc
61
	 */
62
	public function get_index_template()
63
	{
64
		return 'views/portal.html';
65
	}
66
67
	/**
68
	 * {@inheritdoc}
69
	 * @param array $filters
70
	 * @param integer $page
71
	 */
72
	public function render_filter(array $filters, $page)
73
	{
74
		$this->build_index_query($filters);
75
76
		$max_update_time = 0;
77
		$total_topics = $this->forum->get_topics_count();
78
		$items_per_page = (int) $this->config['topics_per_page'];
79
		$start = ($page - 1) * $items_per_page;
80
		$topics_data = $this->forum->get_topic_data($items_per_page, $start);
81
		$this->generate_pagination('summary', $total_topics, $start, $items_per_page, $this->get_filter_params($filters));
82
83
		if (sizeof($topics_data))
84
		{
85
			$posts_data = $this->forum->get_post_data('first');
86
			$users_cache = $this->forum->get_posters_info();
87
88
			$forums_data = array();
89
			foreach ($posts_data as $topic_id => $row)
90
			{
91
				$post = current($row);
92
				$forums_data[$post['forum_id']][$topic_id] = $post;
93
			}
94
95
			$this->display_filtered_topics($forums_data, $topics_data, $users_cache, $max_update_time);
96
		}
97
		return $max_update_time;
98
	}
99
100
	/**
101
	 * @param array $forums_data
102
	 * @param array $topics_data
103
	 * @param array $users_cache
104
	 * @param int $max_update_time
105
	 * @return void
106
	 */
107
	protected function display_filtered_topics(array $forums_data, array $topics_data, array $users_cache, &$max_update_time)
108
	{
109
		$update_count = array();
110
		foreach ($forums_data as $forum_id => $posts_data)
111
		{
112
			$content_type = $this->content_types->get_forum_type($forum_id);
113
			if (!$content_type || !($entity = $this->content_types->get_type($content_type)))
114
			{
115
				continue;
116
			}
117
118
			$this->fields->prepare_to_show($entity, array_keys($posts_data), $entity->get_summary_fields(), $entity->get_summary_tpl(), 'summary');
119
120
			$topic_tracking_info = $this->forum->get_topic_tracking_info($forum_id);
121
			$attachments = $this->forum->get_attachments($forum_id);
122
123
			$this->template->assign_vars($entity->to_array());
124
			foreach ($posts_data as $topic_id => $post_data)
125
			{
126
				$topic_data	= $topics_data[$topic_id];
127
				$topic_data = $this->fields->show($content_type, $topic_data, $post_data, $users_cache, $attachments, $update_count, $topic_tracking_info);
128
129
				$this->template->assign_block_vars('topicrow', $topic_data);
130
				$max_update_time = max($max_update_time, $topic_data['UPDATED']);
131
			}
132
		}
133
	}
134
135
	/**
136
	 * @param array $filters
137
	 * @return array
138
	 */
139
	protected function get_filter_params(array $filters)
140
	{
141
		if (sizeof(array_keys($filters)) > 1)
142
		{
143
			return array('filters' => $filters);
144
		}
145
		else
146
		{
147
			$key = key($filters);
148
			return array(
149
				'filter_type'	=> $key,
150
				'filter_value'	=> current($filters[$key]),
151
			);
152
		}
153
	}
154
}
155