Failed Conditions
Branch newinternal (286d66)
by Simon
03:46
created

Offline::getOfflineMessage()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12
Metric Value
dl 0
loc 30
ccs 0
cts 23
cp 0
rs 8.8571
cc 3
eloc 18
nc 3
nop 2
crap 12
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
	public static function isOffline()
23
	{
24
		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
		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
	public static function getOfflineMessage($external, $message = null)
38
	{
39
		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
		$smarty = new Smarty();
42
		$smarty->assign("baseurl", $baseurl);
43
		$smarty->assign("toolversion", Environment::getToolVersion());
44
45
		header("HTTP/1.1 503 Service Unavailable");
46
47
		if ($external) {
48
			return $smarty->fetch("offline/external.tpl");
49
		}
50
		else {
51
			$hideCulprit = true;
52
53
			// Use the provided message if possible
54
			if ($message === null) {
55
				$hideCulprit = false;
56
				$message = $dontUseDbReason;
57
			}
58
59
			$smarty->assign("hideCulprit", $hideCulprit);
60
			$smarty->assign("dontUseDbCulprit", $dontUseDbCulprit);
61
			$smarty->assign("dontUseDbReason", $message);
62
			$smarty->assign("alerts", array());
63
64
			return $smarty->fetch("offline/internal.tpl");
65
		}
66
	}
67
}
68