GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

topic   F
last analyzed

Complexity

Total Complexity 68

Size/Duplication

Total Lines 314
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 68
lcom 1
cbo 0
dl 0
loc 314
ccs 0
cts 206
cp 0
rs 2.96
c 0
b 0
f 0

39 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 40 7
A user_posted() 0 4 3
A attach_icon_img() 0 4 4
A topic_reported() 0 4 3
A u_mcp_queue() 0 21 4
A unapproved_img() 0 4 4
A topic_deleted() 0 4 1
A topic_unapproved() 0 4 1
A posts_unapproved() 0 4 1
A replies() 0 4 1
A newest_post_url() 0 4 1
A last_post_url() 0 4 1
A view_topic_url() 0 4 1
A img_style() 0 4 1
A folder_img() 0 4 1
A folder_img_alt() 0 4 1
A topic_type() 0 4 1
A unread_topic() 0 4 1
A forum_id() 0 4 1
A topic_id() 0 4 1
A has_poll() 0 4 2
A post_announce() 0 4 2
A post_global() 0 4 2
A post_sticky() 0 4 2
A locked() 0 4 2
A moved() 0 4 2
A last_post_author() 0 4 1
A topic_author() 0 4 1
A mcp_report() 0 4 1
A forum_name() 0 4 2
A topic_title() 0 4 1
A views() 0 4 1
A author() 0 4 1
A last_author() 0 4 1
A topic_time() 0 4 1
A last_post_subject() 0 4 1
A last_post_time() 0 4 1
A last_view_time() 0 4 1
A topic_type_switch() 0 6 4

How to fix   Complexity   

Complex Class

Complex classes like topic often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use topic, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
*
4
* @package phpBB Extension - RH Topic Tags
5
* @copyright (c) 2014 Robet Heim
6
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
*
8
*/
9
10
namespace robertheim\topictags\controller;
11
12
/**
13
* Represents a topic.
14
*/
15
class topic
16
{
17
	/** @var array */
18
	private $topic_row;
19
20
	/** @var \phpbb\user */
21
	private $user;
22
23
	/** @var \phpbb\auth\auth */
24
	private $auth;
25
26
	/** @var string */
27
	private $phpbb_root_path;
28
29
	/** @var string */
30
	private $php_ext;
31
32
	/** @var int */
33
	private $topic_id;
34
35
	// unread_topic should be based on the users topic tracking info
36
	// this wont be supported until phpbb code is less complex
37
	/** @var boolean */
38
	private $unread_topic = false;
39
40
	/** @var string */
41
	private $folder_img = '';
42
	/** @var string */
43
	private $folder_alt = '';
44
	/** @var string */
45
	private $topic_type = '';
46
47
	/** @var int */
48
	private $forum_id;
49
50
	/** @var mixed */
51
	private $replies;
52
53
	/** @var string */
54
	private $view_topic_url_params;
55
	/** @var string */
56
	private $view_topic_url;
57
58
	/** @var string */
59
	private $newest_post_url;
60
	/** @var string */
61
	private $last_post_url;
62
63
	/** @var boolean */
64
	private $topic_unapproved;
65
	/** @var boolean */
66
	private $posts_unapproved;
67
	/** @var boolean */
68
	private $topic_deleted;
69
70
	/**
71
	 *
72
	 * @param array $topic_row a db topic row
73
	 */
74
	public function __construct(array $topic_row,
75
		\phpbb\user $user,
76
		\phpbb\auth\auth $auth,
77
		\phpbb\content_visibility $phpbb_content_visibility,
78
		$phpbb_root_path,
79
		$php_ext)
80
	{
81
		$this->user = $user;
82
		$this->auth = $auth;
83
		$this->phpbb_root_path = $phpbb_root_path;
84
		$this->php_ext = $php_ext;
85
		$this->topic_row = $topic_row;
86
		if ($topic_row['topic_status'] == ITEM_MOVED)
87
		{
88
			$this->topic_id = $topic_row['topic_moved_id'];
89
		}
90
		else
91
		{
92
			$this->topic_id = $topic_row['topic_id'];
93
		}
94
		$this->forum_id = (int) $this->topic_row['forum_id'];
95
96
		$this->view_topic_url_params = 'f=' . $this->forum_id . '&amp;t=' . $this->topic_id;
97
		$this->view_topic_url	= append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params);
98
		$this->newest_post_url	= append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params . '&amp;view=unread') . '#unread';
99
		$this->last_post_url	= append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params . '&amp;p=' . $topic_row['topic_last_post_id']) . '#p' . $topic_row['topic_last_post_id'];
100
101
		$this->replies = $phpbb_content_visibility->get_count('topic_posts', $topic_row, $this->forum_id) - 1;
102
103
		if (!function_exists('topic_status'))
104
		{
105
			include ($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext);
106
		}
107
		// Get folder img, topic status/type related information
108
		topic_status($topic_row, $this->replies, $this->unread_topic(), $this->folder_img, $this->folder_alt, $this->topic_type);
109
110
		$this->topic_unapproved = (($topic_row['topic_visibility'] == ITEM_UNAPPROVED || $topic_row['topic_visibility'] == ITEM_REAPPROVE) && $auth->acl_get('m_approve', $this->forum_id));
111
		$this->posts_unapproved = ($topic_row['topic_visibility'] == ITEM_APPROVED && $topic_row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $this->forum_id));
112
		$this->topic_deleted = $topic_row['topic_visibility'] == ITEM_DELETED;
113
	}
114
115
	public function user_posted()
116
	{
117
		return (isset($this->topic_row['topic_posted']) && $this->topic_row['topic_posted']) ? true : false;
118
	}
119
120
	public function attach_icon_img()
121
	{
122
		return ($this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $this->topic_row['forum_id']) && $this->topic_row['topic_attachment']) ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '';
123
	}
124
125
	public function topic_reported()
126
	{
127
		return (!empty($this->topic_row['topic_reported']) && $this->auth->acl_get('m_report', $this->topic_row['forum_id'])) ? true : false;
128
	}
129
130
	public function u_mcp_queue()
131
	{
132
		$mode = '';
133
		if ($this->topic_unapproved)
134
		{
135
			$mode = 'approve_details';
136
		}
137
		else if ($this->posts_unapproved)
138
		{
139
			$mode = 'unapproved_posts';
140
		}
141
		else if ($this->topic_deleted)
142
		{
143
			$mode = 'deleted_topics';
144
		}
145
		else
146
		{
147
			return '';
148
		}
149
		return append_sid("{$this->phpbb_root_path}mcp.{$this->php_ext}", "i=queue&amp;mode=$mode&amp;t={$this->topic_id}", true, $this->user->session_id);
150
	}
151
152
	public function unapproved_img()
153
	{
154
		return ($this->topic_unapproved || $this->posts_unapproved) ? $this->user->img('icon_topic_unapproved', ($this->topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '';
155
	}
156
157
	public function topic_deleted()
158
	{
159
		return $this->topic_deleted;
160
	}
161
162
	public function topic_unapproved()
163
	{
164
		return $this->topic_unapproved;
165
	}
166
167
	public function posts_unapproved()
168
	{
169
		return $this->posts_unapproved;
170
	}
171
172
	public function replies()
173
	{
174
		return $this->replies;
175
	}
176
177
	public function newest_post_url()
178
	{
179
		return $this->newest_post_url;
180
	}
181
182
	public function last_post_url()
183
	{
184
		return $this->last_post_url;
185
	}
186
187
	public function view_topic_url()
188
	{
189
		return $this->view_topic_url;
190
	}
191
192
	public function img_style()
193
	{
194
		return $this->folder_img;
195
	}
196
197
	public function folder_img()
198
	{
199
		return $this->user->img($this->folder_img, $this->folder_alt);
200
	}
201
202
	public function folder_img_alt()
203
	{
204
		return $this->user->lang[$this->folder_alt];
205
	}
206
207
	public function topic_type()
208
	{
209
		return $this->topic_type;
210
	}
211
212
	public function unread_topic()
213
	{
214
		return $this->unread_topic;
215
	}
216
217
	public function forum_id()
218
	{
219
		return $this->forum_id;
220
	}
221
222
	public function topic_id()
223
	{
224
		return $this->topic_id;
225
	}
226
227
	public function has_poll()
228
	{
229
		return ($this->topic_row['poll_start']) ? true : false;
230
	}
231
232
	public function post_announce()
233
	{
234
		return ($this->topic_row['topic_type'] == POST_ANNOUNCE) ? true : false;
235
	}
236
237
	public function post_global()
238
	{
239
		return ($this->topic_row['topic_type'] == POST_GLOBAL) ? true : false;
240
	}
241
242
	public function post_sticky()
243
	{
244
		return ($this->topic_row['topic_type'] == POST_STICKY) ? true : false;
245
	}
246
247
	public function locked()
248
	{
249
		return ($this->topic_row['topic_status'] == ITEM_LOCKED) ? true : false;
250
	}
251
252
	public function moved()
253
	{
254
		return ($this->topic_row['topic_status'] == ITEM_MOVED) ? true : false;
255
	}
256
257
	public function last_post_author()
258
	{
259
		return get_username_string('profile', $this->topic_row['topic_last_poster_id'], $this->topic_row['topic_last_poster_name'], $this->topic_row['topic_last_poster_colour']);
260
	}
261
262
	public function topic_author()
263
	{
264
		return get_username_string('profile', $this->topic_row['topic_poster'], $this->topic_row['topic_first_poster_name'], $this->topic_row['topic_first_poster_colour']);
265
	}
266
267
	public function mcp_report()
268
	{
269
		return append_sid("{$this->phpbb_root_path}mcp.{$this->php_ext}", 'i=reports&amp;mode=reports&amp;f=' . $this->forum_id . '&amp;t=' . $this->topic_id, true, $this->user->session_id);
270
	}
271
272
	public function forum_name()
273
	{
274
		return (isset($this->topic_row['forum_name'])) ? $this->topic_row['forum_name'] : '';
275
	}
276
277
	public function topic_title()
278
	{
279
		return censor_text($this->topic_row['topic_title']);
280
	}
281
282
	public function views()
283
	{
284
		return $this->topic_row['topic_views'];
285
	}
286
287
	public function author($mode)
288
	{
289
		return get_username_string($mode, $this->topic_row['topic_poster'], $this->topic_row['topic_first_poster_name'], $this->topic_row['topic_first_poster_colour']);
290
	}
291
292
	public function last_author($mode)
293
	{
294
		return get_username_string($mode, $this->topic_row['topic_last_poster_id'], $this->topic_row['topic_last_poster_name'], $this->topic_row['topic_last_poster_colour']);
295
	}
296
297
	public function topic_time()
298
	{
299
		return $this->user->format_date($this->topic_row['topic_time']);
300
	}
301
302
	public function last_post_subject()
303
	{
304
		return censor_text($this->topic_row['topic_last_post_subject']);
305
	}
306
307
	public function last_post_time()
308
	{
309
		return $this->user->format_date($this->topic_row['topic_last_post_time']);
310
	}
311
312
	public function last_view_time()
313
	{
314
		return $this->user->format_date($this->topic_row['topic_last_view_time']);
315
	}
316
317
	/**
318
	 * This will allow the style designer to output a different header
319
	 * or even separate the list of announcements from sticky and normal topics
320
	 * @return number
321
	 */
322
	public function topic_type_switch()
323
	{
324
		$s_type_switch = 0;
325
		$s_type_switch_test = ($this->topic_row['topic_type'] == POST_ANNOUNCE || $this->topic_row['topic_type'] == POST_GLOBAL) ? 1 : 0;
326
		return ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test;
327
	}
328
}
329