Completed
Push — rbac ( 1ec5d5...5c33ef )
by Simon
04:39
created

Offline::getOfflineMessage()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4.25

Importance

Changes 0
Metric Value
cc 4
eloc 19
nc 6
nop 2
dl 0
loc 32
ccs 15
cts 20
cp 0.75
crap 4.25
rs 8.5806
c 0
b 0
f 0
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;
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
        if (!headers_sent()) {
46
            header("HTTP/1.1 503 Service Unavailable");
47
        }
48
49 1
        if ($external) {
50 1
            return $smarty->fetch("offline/external.tpl");
51
        }
52
        else {
53 1
            $hideCulprit = true;
54
55
            // Use the provided message if possible
56 1
            if ($message === null) {
57
                $hideCulprit = false;
58
                $message = $dontUseDbReason;
59
            }
60
61 1
            $smarty->assign("hideCulprit", $hideCulprit);
62 1
            $smarty->assign("dontUseDbCulprit", $dontUseDbCulprit);
63 1
            $smarty->assign("dontUseDbReason", $message);
64 1
            $smarty->assign("alerts", array());
65
66 1
            return $smarty->fetch("offline/internal.tpl");
67
        }
68
    }
69
}
70