Completed
Pull Request — master (#526)
by Michael
01:57
created

StatsTemplateStats   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 59
loc 59
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPageName() 0 3 1
A getPageTitle() 0 3 1
A isProtected() 0 3 1
A requiresWikiDatabase() 0 3 1
A execute() 0 35 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
**********      English Wikipedia Account Request Interface      **********
4
***************************************************************************
5
** Wikipedia Account Request Graphic Design by Charles Melbye,           **
6
** which is licensed under a Creative Commons                            **
7
** Attribution-Noncommercial-Share Alike 3.0 United States License.      **
8
**                                                                       **
9
** All other code are released under the Public Domain                   **
10
** by the ACC Development Team.                                          **
11
**                                                                       **
12
** See CREDITS for the list of developers.                               **
13
***************************************************************************/
14
15
class StatsTemplateStats extends StatisticsPage
16
{
17
	protected function execute()
18
	{
19
		$query = <<<SQL
20
SELECT
21
    t.id as "Template ID",
22
    t.usercode as "Template Code",
23
    u.count as "Active users using template",
24
    countall as "All users using template"
25
FROM welcometemplate t
26
    LEFT JOIN
27
    (
28
        SELECT
29
            welcome_template,
30
            COUNT(*) as count
31
        FROM user
32
        WHERE
33
            (status = "User" OR status = "Admin")
34
            AND welcome_template IS NOT NULL
35
        GROUP BY welcome_template
36
    ) u ON u.welcome_template = t.id
37
    LEFT JOIN
38
    (
39
        SELECT
40
            welcome_template as allid,
41
            COUNT(*) as countall
42
        FROM user
43
        WHERE welcome_template IS NOT NULL
44
        GROUP BY welcome_template
45
    ) u2 ON u2.allid = t.id;
46
SQL;
47
48
		$qb = new QueryBrowser();
49
		$r = $qb->executeQueryToTable($query);
50
51
		return $r;
52
	}
53
54
	public function getPageName()
55
	{
56
		return "TemplateStats";
57
	}
58
59
	public function getPageTitle()
60
	{
61
		return "Template Stats";
62
	}
63
64
	public function isProtected()
65
	{
66
		return true;
67
	}
68
69
	public function requiresWikiDatabase()
70
	{
71
		return false;
72
	}
73
}
74