Passed
Push — master ( e44ec4...aec258 )
by Chris
01:10
created

Output::number_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
            switch (gettype($var)) {
33
                case 'string':
34
                    return self::string_text($var);
35
                case 'integer':
36
                case 'double':
37
                    return self::number_text($var);
38
                case 'boolean':
39
                    return self::bool_text($var);
40
                case 'NULL':
41
                    return 'null';
42
                default:
43
                    return print_r($var, true);
44
            }
45
        }
46
47
        private static function string_text($string) {
48
            return 'string: "' . $string . '"';
49
        }
50
51
        private static function number_text($int) {
52
            return 'number: ' . $int;
53
        }
54
        
55
        private static function bool_text($bool) {
56
            $txt_bool = $bool ? 'true' : 'false';
57
58
            return 'boolean: ' . $txt_bool;
59
        }
60
    }