Passed
Push — master ( 096a1f...9002f9 )
by Fran
04:06 queued 15s
created

debug()   C

Complexity

Conditions 12
Paths 16

Size

Total Lines 24
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 12
eloc 20
c 1
b 0
f 0
nc 16
nop 3
dl 0
loc 24
rs 6.9666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
use PSFS\base\extension\CustomTranslateExtension;
4
use Symfony\Component\Finder\Finder;
5
6
//Cargamos en memoria la función de desarrollo PRE
7
if (!function_exists('pre')) {
8
    function pre($var, $die = FALSE)
9
    {
10
        $html = '<pre style="padding:10px;margin:0;display:block;background: #EEE; box-shadow: inset 0 0 3px 3px #DDD; color: #666; text-shadow: 1px 1px 1px #CCC;border-radius: 5px;">';
11
        $html .= is_null($var) ? '<b>NULL</b>' : print_r($var, TRUE);
12
        $html .= '</pre>';
13
        ob_start();
14
        echo $html;
15
        ob_flush();
16
        ob_end_clean();
17
        if ($die) {
18
            die;
19
        }
20
    }
21
}
22
23
if (!function_exists('jpre')) {
24
    function jpre($var, $die = false)
25
    {
26
        echo json_encode($var, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
27
        if ($die) {
28
            die;
29
        }
30
    }
31
}
32
33
if (!function_exists('debug')) {
34
    function debug($var, $varName = "", $die = FALSE)
35
    {
36
        $html = '<style>*{margin: 0} body{background: rgb(36,36,36); padding: 5px;}</style>';
37
        $html .= '<pre style="padding: 10px; margin: 5px; display: block; background: rgb(41,41,41); color: white; border-radius: 5px;">';
38
        if(is_null($var)) {
39
            if($varName) $html .= $varName . ' ==> <b>NULL</b>';
40
        } else {
41
            $html .= print_r('(' . gettype($var) . ') ', TRUE);
42
            if($varName) $html .= $varName . ' ==> ';
43
            if("boolean" === gettype($var)) {
44
                $html .= print_r($var ? "TRUE" : "FALSE", TRUE);
45
            } else if((is_array($var) && !empty($var)) || (!is_array($var)) ||  ($var === 0)) {
46
                $html .= print_r($var, TRUE);
47
            } else {
48
                $html .= 'empty';
49
            }
50
        }
51
        $html .= '</pre>';
52
        ob_start();
53
        echo $html;
54
        ob_flush();
55
        ob_end_clean();
56
        if ($die || $var === "die") {
57
            die;
58
        }
59
    }
60
}
61
62
if (!function_exists("getallheaders")) {
63
    function getallheaders()
64
    {
65
        $headers = [];
66
        foreach ($_SERVER as $h => $v)
67
            if (preg_match('/HTTP_(.+)/', $h, $hp)) {
68
                $headers[$hp[1]] = $v;
69
            }
70
        return $headers;
71
    }
72
}
73
74
if (file_exists(CORE_DIR)) {
75
    $loaded_files = [];
76
    //Autoload de módulos
77
    $finder = new Finder();
78
    $finder->files()->in(CORE_DIR)->name('autoload.php');
79
    /* @var $file SplFileInfo */
80
    foreach ($finder as $file) {
81
        $path = $file->getRealPath();
82
        if(!in_array($path, $loaded_files)) {
83
            $loaded_files[] = $path;
84
            require_once($path);
85
        }
86
    }
87
}
88
89
if(!function_exists('t')) {
90
    function t($message, $key = null, $reload = false) {
91
        return CustomTranslateExtension::_($message, $key, $reload);
92
    }
93
}