Passed
Push — master ( 19e3b7...6548a2 )
by Andreas
23:32
created

midcom_compat_environment   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 29
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A header() 0 9 2
A stop_request() 0 4 2
A flush_registered_headers() 0 5 1
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 17
    public static function header(string $string, bool $replace = true, int $http_response_code = 0)
19
    {
20 17
        if (!defined('OPENPSA2_UNITTEST_RUN')) {
21
            header($string, $replace, $http_response_code);
22
        } else {
23 17
            self::$_headers[] = [
24 17
                'value' => $string,
25 17
                'replace' => $replace,
26 17
                'http_response_code' => $http_response_code
27 17
            ];
28
        }
29
    }
30
31
    public static function stop_request(string $message)
32
    {
33
        if (!defined('OPENPSA2_UNITTEST_RUN')) {
34
            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...
35
        }
36
    }
37
38 664
    public static function flush_registered_headers() : array
39
    {
40 664
        $headers = self::$_headers;
41 664
        self::$_headers = [];
42 664
        return $headers;
43
    }
44
}
45