Completed
Pull Request — newinternal (#285)
by Simon
06:03 queued 03:05
created

Offline   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isOffline() 0 6 1
B getOfflineMessage() 0 32 4
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;
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
        if (!headers_sent()) {
46
            header("HTTP/1.1 503 Service Unavailable");
47
        }
48
49
        if ($external) {
50
            return $smarty->fetch("offline/external.tpl");
51
        }
52
        else {
53
            $hideCulprit = true;
54
55
            // Use the provided message if possible
56
            if ($message === null) {
57
                $hideCulprit = false;
58
                $message = $dontUseDbReason;
59
            }
60
61
            $smarty->assign("hideCulprit", $hideCulprit);
62
            $smarty->assign("dontUseDbCulprit", $dontUseDbCulprit);
63
            $smarty->assign("dontUseDbReason", $message);
64
            $smarty->assign("alerts", array());
65
66
            return $smarty->fetch("offline/internal.tpl");
67
        }
68
    }
69
}
70