Passed
Push — master ( 43be64...089d42 )
by Chris
01:16
created

Output::float_text()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
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;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

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.

Loading history...
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
    }