Completed
Push — master ( b9fa67...e31f65 )
by Andreas
24:00 queued 04:20
created

flush_registered_headers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 2
b 0
f 0
1
<?php
2
/**
3
 * @package midcom.compat
4
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
6
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
7
 */
8
9
/**
10
 * Support for interactions with environment
11
 *
12
 * @package midcom.compat
13
 */
14
class midcom_compat_environment
15
{
16
    private static $_headers = [];
17
18
    private static $_implementation;
19
20 17
    public static function get() : self
21
    {
22 17
        return self::$_implementation;
23
    }
24
25 1
    public static function initialize()
26
    {
27 1
        self::$_implementation = new static;
28 1
    }
29
30 17
    public function header(string $string, $replace = true, $http_response_code = null)
31
    {
32 17
        if (!defined('OPENPSA2_UNITTEST_RUN')) {
33
            header($string, $replace, $http_response_code);
34
        } else {
35 17
            self::$_headers[] = [
36 17
                'value' => $string,
37 17
                'replace' => $replace,
38 17
                'http_response_code' => $http_response_code
39
            ];
40
        }
41 17
    }
42
43
    public function stop_request(string $message = '')
44
    {
45
        if (!defined('OPENPSA2_UNITTEST_RUN')) {
46
            exit($message);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
47
        }
48
    }
49
50 735
    public static function flush_registered_headers() : array
51
    {
52 735
        $headers = self::$_headers;
53 735
        self::$_headers = [];
54 735
        return $headers;
55
    }
56
}
57