Passed
Push — master ( 9c6499...c22bc5 )
by Jens
04:52 queued 02:21
created

functions.php ➔ dump()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 37
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 22
nc 3
nop 0
dl 0
loc 37
rs 8.5806
c 0
b 0
f 0
1
<?php
2
/** @noinspection PhpDocSignatureInspection */
3
4
/**
5
* Dumps a var_dump of the passed arguments with <pre> tags surrounding it.
6
 * Dies afterwards
7
 *
8
 * @param mixed ...    The data to be displayed
9
 */
10
function dump()
11
{
12
	$debug_backtrace = current(debug_backtrace());
13
	if (PHP_SAPI == 'cli') {
14
		echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n";
15
		foreach (func_get_args() as $data) {
16
			var_dump($data);
17
		}
18
	} else {
19
		ob_clean();
20
        echo <<<END
21
<!DOCTYPE html>
22
<html>
23
<head>
24
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/highlight.min.js"></script>
25
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/styles/default.min.css" />
26
<script>hljs.initHighlightingOnLoad();</script>
27
<style>code.php.hljs{margin: -0.4em 0;}code.active{background-color:#e0e0e0;}code:before{content:attr(data-line);}code.active:before{color:#c00;font-weight:bold;}</style>
28
</head>
29
<body>
30
END;
31
32
		echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>";
33
		echo '<pre>';
34
		foreach (func_get_args() as $data) {
35
			echo "<code>";
36
			var_dump($data);
37
			echo "</code>";
38
		}
39
		echo '</pre>';
40
		echo <<<END
41
</body>
42
</html>
43
END;
44
	}
45
	die;
46
}
47
48
/**
49
 * Convert all values of an array to utf8
50
 *
51
 * @param $array
52
 * @return array
53
 */
54
function utf8Convert($array)
55
{
56
	array_walk_recursive($array, function(&$item){
57
		if(!mb_detect_encoding($item, 'utf-8', true)){
58
			$item = utf8_encode($item);
59
		}
60
	});
61
62
	return $array;
63
}