1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rAPId\Debug; |
4
|
|
|
|
5
|
|
|
class Output |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @param mixed $data |
9
|
|
|
* @param string $identifier |
10
|
|
|
*/ |
11
|
|
|
public static function variable($data, $identifier = '') { |
12
|
|
|
if (!empty($identifier)) { |
13
|
|
|
$output = self::get_variable_text_with_title($data, $identifier); |
14
|
|
|
} else { |
15
|
|
|
$output = self::get_variable_text($data); |
16
|
|
|
} |
17
|
|
|
echo "\n$output\n"; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
private static function get_variable_text_with_title($data, $title) { |
21
|
|
|
|
22
|
|
|
$result = str_repeat('_', strlen($title)) . "_\n"; |
23
|
|
|
$result .= $title . " |\n"; |
24
|
|
|
$result .= "============================================================================\n"; |
25
|
|
|
$result .= self::get_variable_text($data); |
26
|
|
|
$result .= "\n============================================================================"; |
27
|
|
|
|
28
|
|
|
return $result; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
private static function get_variable_text($var) { |
32
|
|
|
$result = ''; |
33
|
|
|
|
34
|
|
|
switch (gettype($var)) { |
35
|
|
|
case 'string': |
36
|
|
|
return self::string_text($var); |
37
|
|
|
case 'integer': |
38
|
|
|
return self::int_text($var); |
39
|
|
|
case 'double': |
40
|
|
|
return self::float_text($var); |
41
|
|
|
case 'boolean': |
42
|
|
|
return self::bool_text($var); |
43
|
|
|
break; |
|
|
|
|
44
|
|
|
case 'NULL': |
45
|
|
|
echo 'null'; |
46
|
|
|
break; |
47
|
|
|
default: |
48
|
|
|
$result .= print_r($var, true); |
49
|
|
|
break; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $result; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private static function string_text($string) { |
56
|
|
|
return 'string: "' . $string . '"'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private static function int_text($int) { |
60
|
|
|
return 'integer: ' . $int; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private static function float_text($float) { |
64
|
|
|
return 'float: ' . $float; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private static function bool_text($bool) { |
68
|
|
|
$txt_bool = $bool ? 'true' : 'false'; |
69
|
|
|
|
70
|
|
|
return 'boolean: ' . $txt_bool; |
71
|
|
|
} |
72
|
|
|
} |
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.