Completed
Pull Request — master (#526)
by Michael
11:09 queued 01:05
created

Offline   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 38.6 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 78.26%

Importance

Changes 0
Metric Value
dl 22
loc 57
rs 10
c 0
b 0
f 0
ccs 18
cts 23
cp 0.7826
wmc 6
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isOffline() 0 5 1
A getOfflineMessage() 0 12 2
A check() 0 16 3

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
/**
16
 * Handles the tool offline messages
17
 */
18
class Offline
19
{
20
	/**
21
	 * Summary of check
22
	 * @param bool $external External interface
23
	 * @deprecated Do checking within the entry point.
24
	 */
25
	public static function check($external)
26
	{
27
		global $smarty, $dontUseDb, $dontUseDbCulprit, $dontUseDbReason;
28
29
		if ($dontUseDb) {
30
			if ($external) {
31
				$smarty->display("offline/external.tpl");
32
			}
33
			else {
34
				$smarty->assign("dontUseDbCulprit", $dontUseDbCulprit);
35
				$smarty->assign("dontUseDbReason", $dontUseDbReason);
36
				$smarty->assign("alerts", array());
37
				$smarty->display("offline/internal.tpl");
38
			}
39
40
			die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
41
		}
42
	}
43
44
	/**
45
	 * Determines if the tool is offline
46
	 * @return bool
47
	 */
48
	public static function isOffline()
49
	{
50
		global $dontUseDb;
51
52
		return (bool)$dontUseDb;
53
	}
54
55
	/**
56
	 * Gets the offline message
57
	 * @param bool $external
58
	 * @return string
59
	 */
60
	public static function getOfflineMessage($external)
61
	{
62
		global $smarty, $dontUseDbCulprit, $dontUseDbReason;
63
64
		if ($external) {
65
			return $smarty->fetch("offline/external.tpl");
66
		}
67
		else {
68
			$smarty->assign("dontUseDbCulprit", $dontUseDbCulprit);
69
			$smarty->assign("dontUseDbReason", $dontUseDbReason);
70
			$smarty->assign("alerts", array());
71
			return $smarty->fetch("offline/internal.tpl");
72
		}
73
	}
74
}
75