Completed
Push — master ( 237036...650d4b )
by Dominik
02:47
created

Log::echoDebug()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Flynt\Utils;
4
5
class Log
6
{
7
    public static function console($data)
8
    {
9
        self::consoleDebug($data);
10
    }
11
12
    public static function error($data)
13
    {
14
        self::consoleDebug($data, 'PHP', 'error');
15
    }
16
17
    public static function consoleDebug($data, $title = 'PHP', $logType = 'log')
18
    {
19
        $title .= '(' . self::getCallerFile(2) .'):';
20
        $type = gettype($data);
21
        if (is_array($data) || is_object($data)) {
22
            $output = json_encode($data);
23
            echo "<script>console.$logType('$title', '($type)', $output);</script>\n";
24
        } else {
25
            echo "<script>console.$logType('$title', '($type)', '$data');</script>\n";
26
        }
27
    }
28
29
    public static function pp($data)
30
    {
31
        $type = gettype($data);
32
        echo "<pre>";
33
        echo "(" . $type . ") ";
34
        print_r($data);
35
        echo "<br />File: <strong>" . self::getCallerFile() . "</strong>";
36
        echo "</pre>\n";
37
    }
38
39
    protected static function getCallerFile($depth = 1)
40
    {
41
        $debug = debug_backtrace();
42
        $fileName = $debug[$depth]['file'];
43
        $templateDir = get_template_directory() . '/';
44
        return str_replace($templateDir, '', $fileName) . '#' . $debug[$depth]['line'];
45
    }
46
}
47