Completed
Push — master ( aec258...0192d8 )
by Chris
01:11
created

Output   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 13

10 Methods

Rating   Name   Duplication   Size   Complexity  
A variable() 0 7 2
A get_variable_text_with_title() 0 9 1
A integer_text() 0 2 1
A boolean_text() 0 4 2
A get_variable_text() 0 7 2
A double_text() 0 2 1
A string_text() 0 2 1
A NULL_text() 0 2 1
A object_text() 0 2 1
A array_text() 0 2 1
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
            $type = gettype($var);
33
            if (method_exists(self::class, $type . '_text')) {
34
                return self::{$type . '_text'}($var);
35
            }
36
37
            return $type . ': ' . print_r($var, true);
38
        }
39
40
        private static function string_text($string) {
41
            return 'string: "' . $string . '"';
42
        }
43
44
        private static function integer_text($int) {
45
            return 'integer: ' . $int;
46
        }
47
48
        private static function double_text($double) {
49
            return 'float: ' . $double;
50
        }
51
52
        private static function boolean_text($bool) {
53
            $txt_bool = $bool ? 'true' : 'false';
54
55
            return 'boolean: ' . $txt_bool;
56
        }
57
58
        private static function NULL_text($null) {
59
            return 'null';
60
        }
61
62
        private static function array_text($array) {
63
            return print_r($array, true);
64
        }
65
66
        private static function object_text($object) {
67
            return print_r($object, true);
68
        }
69
70
    }