Test Failed
Push — master ( 0df305...894c40 )
by Julien
04:46
created

exit_500()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 12
rs 10
1
<?php
2
3
use Phalcon\Debug\Dump;
4
5
if (!function_exists('vdd')) {
6
    /**
7
     * Dump the passed variables and end the script.
8
     */
9
    function vdd(...$params): void
10
    {
11
        var_dump(...$params);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($params) looks like debug code. Are you sure you do not want to remove it?
Loading history...
12
        exit_500();
13
    }
14
}
15
16
if (!function_exists('dd')) {
17
    /**
18
     * Dump the passed variables and end the script.
19
     */
20
    function dd(...$params): void
21
    {
22
        dump(...$params);
23
        exit_500();
24
    }
25
}
26
27
if (!function_exists('dump')) {
28
    /**
29
     * Dump the passed variables without ending the script.
30
     */
31
    function dump(...$params): void
32
    {
33
        foreach ($params as $param) {
34
            $ret = (new Dump([], true))->variable($param);
35
            if (PHP_SAPI === 'cli') {
36
                $ret = strip_tags($ret) . PHP_EOL;
37
            }
38
            echo $ret;
39
        }
40
    }
41
}
42
43
if (!function_exists('exit_500')) {
44
    /**
45
     * Exit and set header
46
     */
47
    function exit_500(): void
48
    {
49
        if (!in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && !headers_sent()) {
50
            header('500 Internal Server Error');
51
        }
52
        exit(1);
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...
53
    }
54
}
55