Completed
Branch newinternal (830cd7)
by Simon
03:46
created

Offline   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 85.71%
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 52
ccs 18
cts 21
cp 0.8571
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isOffline() 0 6 1
B getOfflineMessage() 0 30 3
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca;
10
11
use Smarty;
12
13
/**
14
 * Handles the tool offline messages
15
 */
16
class Offline
17
{
18
	/**
19
	 * Determines if the tool is offline
20
	 * @return bool
21
	 */
22 1
	public static function isOffline()
23
	{
24 1
		global $dontUseDb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
25
26 1
		return (bool)$dontUseDb;
27
	}
28
29
	/**
30
	 * Gets the offline message
31
	 *
32
	 * @param bool $external
33
	 * @param null $message
34
	 *
35
	 * @return string
36
	 */
37 1
	public static function getOfflineMessage($external, $message = null)
38
	{
39 1
		global $dontUseDbCulprit, $dontUseDbReason, $baseurl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
40
41 1
		$smarty = new Smarty();
42 1
		$smarty->assign("baseurl", $baseurl);
43 1
		$smarty->assign("toolversion", Environment::getToolVersion());
44
45 1
		header("HTTP/1.1 503 Service Unavailable");
46
47 1
		if ($external) {
48 1
			return $smarty->fetch("offline/external.tpl");
49
		}
50
		else {
51 1
			$hideCulprit = true;
52
53
			// Use the provided message if possible
54 1
			if ($message === null) {
55
				$hideCulprit = false;
56
				$message = $dontUseDbReason;
57
			}
58
59 1
			$smarty->assign("hideCulprit", $hideCulprit);
60 1
			$smarty->assign("dontUseDbCulprit", $dontUseDbCulprit);
61 1
			$smarty->assign("dontUseDbReason", $message);
62 1
			$smarty->assign("alerts", array());
63
64 1
			return $smarty->fetch("offline/internal.tpl");
65
		}
66
	}
67
}
68