Completed
Branch newinternal (e32466)
by Simon
03:39
created

Offline::isOffline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
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