latest_bots   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 129
Duplicated Lines 20.16 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 26
loc 129
ccs 0
cts 54
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
B get_template_side() 0 27 3
A get_template_acp() 10 10 1
A install() 0 5 1
A uninstall() 9 9 1

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 Board3 Portal v2.1
5
* @copyright (c) 2013 Board3 Group ( www.board3.de )
6
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
*
8
*/
9
10
namespace board3\portal\modules;
11
12
/**
13
* @package Latest Bots
14
*/
15
class latest_bots extends module_base
16
{
17
	/**
18
	* Allowed columns: Just sum up your options (Exp: left + right = 10)
19
	* top		1
20
	* left		2
21
	* center	4
22
	* right		8
23
	* bottom	16
24
	*/
25
	public $columns = 10;
26
27
	/**
28
	* Default modulename
29
	*/
30
	public $name = 'LATEST_BOTS';
31
32
	/**
33
	* Default module-image:
34
	* file must be in "{T_THEME_PATH}/images/portal/"
35
	*/
36
	public $image_src = 'portal_bots.png';
37
38
	/**
39
	* module-language file
40
	* file must be in "language/{$user->lang}/mods/portal/"
41
	*/
42
	public $language = 'portal_latest_bots_module';
43
44
	/**
45
	* hide module name in ACP configuration page
46
	*/
47
	public $hide_name = false;
48
49
	/** @var \phpbb\config\config */
50
	protected $config;
51
52
	/** @var \phpbb\db\driver\driver_interface */
53
	protected $db;
54
55
	/** @var \phpbb\template\template */
56
	protected $template;
57
58
	/** @var \phpbb\user */
59
	protected $user;
60
61
	/**
62
	* Construct a latest bots object
63
	*
64
	* @param \phpbb\config\config $config phpBB config
65
	* @param \phpbb\db\driver\driver_interface $db phpBB db driver
66
	* @param \phpbb\template\template $template phpBB template
67
	* @param \phpbb\user $user phpBB user object
68
	*/
69 View Code Duplication
	public function __construct($config, $db, $template, $user)
70
	{
71
		$this->config = $config;
72
		$this->db = $db;
73
		$this->template = $template;
74
		$this->user = $user;
75
	}
76
77
	/**
78
	* {@inheritdoc}
79
	*/
80
	public function get_template_side($module_id)
81
	{
82
		// Last x visited bots
83
		$sql = 'SELECT username, user_colour, user_lastvisit
84
			FROM ' . USERS_TABLE . '
85
			WHERE user_type = ' . USER_IGNORE . '
86
			AND user_lastvisit > 0
87
			ORDER BY user_lastvisit DESC';
88
		$result = $this->db->sql_query_limit($sql, $this->config['board3_last_visited_bots_number_' . $module_id], 0, 600);
89
90
		$show_module = false;
91
92
		while ($row = $this->db->sql_fetchrow($result))
93
		{
94
			$this->template->assign_block_vars('last_visited_bots', array(
95
				'BOT_NAME'			=> get_username_string('full', '', $row['username'], $row['user_colour']),
96
				'LAST_VISIT_DATE'	=> $this->user->format_date($row['user_lastvisit']),
97
			));
98
			$show_module = true;
99
		}
100
		$this->db->sql_freeresult($result);
101
102
		if ($show_module)
103
		{
104
			return 'latest_bots_side.html';
105
		}
106
	}
107
108
	/**
109
	* {@inheritdoc}
110
	*/
111 View Code Duplication
	public function get_template_acp($module_id)
112
	{
113
		return array(
114
			'title'	=> 'ACP_PORTAL_BOTS_SETTINGS',
115
			'vars'	=> array(
116
				'legend1'							=> 'ACP_PORTAL_BOTS_SETTINGS',
117
				'board3_last_visited_bots_number_' . $module_id	=> array('lang' => 'PORTAL_LAST_VISITED_BOTS_NUMBER' ,	'validate' => 'int',		'type' => 'text:3:3',		 'explain' => true),
118
			)
119
		);
120
	}
121
122
	/**
123
	* {@inheritdoc}
124
	*/
125
	public function install($module_id)
126
	{
127
		$this->config->set('board3_last_visited_bots_number_' . $module_id, 1);
128
		return true;
129
	}
130
131
	/**
132
	* {@inheritdoc}
133
	*/
134 View Code Duplication
	public function uninstall($module_id, $db)
135
	{
136
		$del_config = array(
137
			'board3_last_visited_bots_number_' . $module_id,
138
		);
139
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
140
			WHERE ' . $db->sql_in_set('config_name', $del_config);
141
		return $db->sql_query($sql);
142
	}
143
}
144