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.

white_and_blacklist_controller   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 110
Duplicated Lines 17.27 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 19
loc 110
ccs 0
cts 65
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 1
A manage_whitelist() 0 4 1
A manage_blacklist() 0 4 1
B manage_list() 4 49 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
namespace robertheim\topictags\acp;
9
10
/**
11
* @ignore
12
*/
13
use robertheim\topictags\prefixes;
14
15
/**
16
 * Handles the "whitelist" and "blacklist" page of the ACP.
17
 */
18
class white_and_blacklist_controller
19
{
20
	/** @var \phpbb\config\config */
21
	private $config;
22
23
	/**
24
	 * @var \phpbb\config\db_text
25
	 */
26
	private $config_text;
27
28
	/** @var \phpbb\request\request */
29
	private $request;
30
31
	/** @var \phpbb\user */
32
	private $user;
33
34
	/** @var \phpbb\template\template */
35
	private $template;
36
37
	/** @var \robertheim\topictags\service\tags_manager */
38
	private $tags_manager;
39
40 View Code Duplication
	public function __construct(
41
		\phpbb\config\config $config,
42
		\phpbb\config\db_text $config_text,
43
		\phpbb\request\request $request,
44
		\phpbb\user $user,
45
		\phpbb\template\template $template,
46
		\robertheim\topictags\service\tags_manager $tags_manager)
47
	{
48
		$this->config = $config;
49
		$this->config_text = $config_text;
50
		$this->request = $request;
51
		$this->user = $user;
52
		$this->template = $template;
53
		$this->tags_manager = $tags_manager;
54
	}
55
56
	/**
57
	 *
58
	 * @param string $u_action phpbb acp-u_action
59
	 */
60
	public function manage_whitelist($u_action)
61
	{
62
		$this->manage_list($u_action, 'whitelist');
63
	}
64
65
	/**
66
	 *
67
	 * @param string $u_action phpbb acp-u_action
68
	 */
69
	public function manage_blacklist($u_action)
70
	{
71
		$this->manage_list($u_action, 'blacklist');
72
	}
73
74
	/**
75
	 * @param string $list_name whitelist or blacklist
76
	 * @param string $u_action phpbb acp-u_action
77
	 */
78
	private function manage_list($u_action, $list_name)
79
	{
80
		$list_name_upper = strtoupper($list_name);
81
		// Define the name of the form for use as a form key
82
		$form_name = 'topictags';
83
		add_form_key($form_name);
84
85
		$errors = array();
86
87
		if ($this->request->is_set_post('submit'))
88
		{
89
			if (! check_form_key($form_name))
90
			{
91
				trigger_error('FORM_INVALID');
92
			}
93
94
			$this->config->set(prefixes::CONFIG . '_' . $list_name . '_enabled', $this->request->variable(prefixes::CONFIG . '_' . $list_name . '_enabled', 0));
95
			$list = rawurldecode(base64_decode($this->request->variable(prefixes::CONFIG . '_' . $list_name, '')));
96
			if (! empty($list))
97
			{
98
				$list = json_decode($list, true);
99
				$tags = array();
100 View Code Duplication
				for ($i = 0, $size = sizeof($list); $i < $size; $i ++)
101
				{
102
					$tags[] = $list[$i]['text'];
103
				}
104
				$list = json_encode($tags);
105
			}
106
			// store the list
107
			$this->config_text->set(prefixes::CONFIG . '_' . $list_name, $list);
108
			trigger_error($this->user->lang('TOPICTAGS_' . $list_name_upper . '_SAVED') . adm_back_link($u_action));
109
		}
110
111
		// display
112
		$list = $this->config_text->get(prefixes::CONFIG . '_' . $list_name);
113
		$list = base64_encode(rawurlencode($list));
114
		$this->template->assign_vars(
115
			array(
116
				'TOPICTAGS_VERSION'								=> $this->user->lang('TOPICTAGS_INSTALLED', $this->config[prefixes::CONFIG . '_version']),
117
				'TOPICTAGS_' . $list_name_upper . '_ENABLED'	=> $this->config[prefixes::CONFIG . '_' . $list_name . '_enabled'],
118
				'TOPICTAGS_' . $list_name_upper					=> $list,
119
				'S_RH_TOPICTAGS_INCLUDE_NG_TAGS_INPUT'			=> true,
120
				'S_RH_TOPICTAGS_INCLUDE_CSS_FROM_ACP'			=> true,
121
				'TOPICTAGS_CONVERT_SPACE_TO_MINUS'				=> $this->config[prefixes::CONFIG . '_convert_space_to_minus'] ? 'true' : 'false',
122
				'S_ERROR'										=> (sizeof($errors)) ? true : false,
123
				'ERROR_MSG'										=> implode('<br />', $errors),
124
				'U_ACTION'										=> $u_action
125
			));
126
	}
127
}
128