latest_members   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 117
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 26
loc 117
ccs 0
cts 49
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
A get_template_side() 0 20 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 members
14
*/
15
class latest_members 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_MEMBERS';
31
32
	/**
33
	* Default module-image:
34
	* file must be in "{T_THEME_PATH}/images/portal/"
35
	*/
36
	public $image_src = 'portal_members.png';
37
38
	/**
39
	* module-language file
40
	* file must be in "language/{$user->lang}/mods/portal/"
41
	*/
42
	public $language = 'portal_latest_members_module';
43
44
	/** @var \phpbb\config\config */
45
	protected $config;
46
47
	/** @var \phpbb\db\driver\driver_interface */
48
	protected $db;
49
50
	/** @var \phpbb\template\template */
51
	protected $template;
52
53
	/** @var \phpbb\user */
54
	protected $user;
55
56
	/**
57
	* Construct a latest_members object
58
	*
59
	* @param \phpbb\config\config $config phpBB config
60
	* @param \phpbb\db\driver\driver_interface $db phpBB db driver
61
	* @param \phpbb\template\template $template phpBB template
62
	* @param \phpbb\user $user phpBB user object
63
	*/
64 View Code Duplication
	public function __construct($config, $db, $template, $user)
65
	{
66
		$this->config = $config;
67
		$this->db = $db;
68
		$this->template = $template;
69
		$this->user = $user;
70
	}
71
72
	/**
73
	* {@inheritdoc}
74
	*/
75
	public function get_template_side($module_id)
76
	{
77
		$sql = 'SELECT user_id, username, user_regdate, user_colour
78
			FROM ' . USERS_TABLE . '
79
			WHERE user_type <> ' . USER_IGNORE . '
80
				AND user_inactive_time = 0
81
			ORDER BY user_regdate DESC';
82
		$result = $this->db->sql_query_limit($sql, $this->config['board3_max_last_member_' . $module_id], 0, 600);
83
84
		while (($row = $this->db->sql_fetchrow($result)) && ($row['username']))
85
		{
86
			$this->template->assign_block_vars('latest_members', array(
87
				'USERNAME_FULL'	=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
88
				'JOINED'		=> $this->user->format_date($row['user_regdate'], $format = 'd M'),
89
			));
90
		}
91
		$this->db->sql_freeresult($result);
92
93
		return 'latest_members_side.html';
94
	}
95
96
	/**
97
	* {@inheritdoc}
98
	*/
99 View Code Duplication
	public function get_template_acp($module_id)
100
	{
101
		return array(
102
			'title'	=> 'ACP_PORTAL_MEMBERS_SETTINGS',
103
			'vars'	=> array(
104
				'legend1'							=> 'ACP_PORTAL_MEMBERS_SETTINGS',
105
				'board3_max_last_member_' . $module_id			=> array('lang' => 'PORTAL_MAX_LAST_MEMBER'			 ,	'validate' => 'int',		'type' => 'text:3:3',		 'explain' => true),
106
			)
107
		);
108
	}
109
110
	/**
111
	* {@inheritdoc}
112
	*/
113
	public function install($module_id)
114
	{
115
		$this->config->set('board3_max_last_member_' . $module_id, 8);
116
		return true;
117
	}
118
119
	/**
120
	* {@inheritdoc}
121
	*/
122 View Code Duplication
	public function uninstall($module_id, $db)
123
	{
124
		$del_config = array(
125
			'board3_max_last_member_' . $module_id,
126
		);
127
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
128
			WHERE ' . $db->sql_in_set('config_name', $del_config);
129
		return $db->sql_query($sql);
130
	}
131
}
132