Passed
Push — master ( ce2bc1...e68e02 )
by Fran
05:34
created

debug()   C

Complexity

Conditions 12
Paths 16

Size

Total Lines 24
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

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
ccs 0
cts 18
cp 0
crap 156
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
    /**
9
     * @param mixed $var
10
     * @param boolean $die
11
     * @return void
12
     */
13
    function pre(mixed $var, bool $die = false): void
14
    {
15 1
        $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;">';
16 1
        $html .= is_null($var) ? '<b>NULL</b>' : print_r($var, TRUE);
17 1
        $html .= '</pre>';
18 1
        echo $html;
19 1
        if ($die) {
20
            die;
21
        }
22
    }
23
}
24
25
if (!function_exists('debug')) {
26
    function debug($var, $varName = "", $die = FALSE)
27
    {
28
        $html = '<style>*{margin: 0} body{background: rgb(36,36,36); padding: 5px;}</style>';
29
        $html .= '<pre style="padding: 10px; margin: 5px; display: block; background: rgb(41,41,41); color: white; border-radius: 5px;">';
30
        if(is_null($var)) {
31
            if($varName) $html .= $varName . ' ==> <b>NULL</b>';
32
        } else {
33
            $html .= print_r('(' . gettype($var) . ') ', TRUE);
34
            if($varName) $html .= $varName . ' ==> ';
35
            if("boolean" === gettype($var)) {
36
                $html .= print_r($var ? "TRUE" : "FALSE", TRUE);
37
            } else if((is_array($var) && !empty($var)) || (!is_array($var)) ||  ($var === 0)) {
38
                $html .= print_r($var, TRUE);
39
            } else {
40
                $html .= 'empty';
41
            }
42
        }
43
        $html .= '</pre>';
44
        ob_start();
45
        echo $html;
46
        ob_flush();
47
        ob_end_clean();
48
        if ($die || $var === "die") {
49
            die;
50
        }
51
    }
52
}
53
54
if (!function_exists("getallheaders")) {
55
    function getallheaders(): array
56
    {
57 2
        $headers = [];
58 2
        foreach ($_SERVER as $h => $v) {
59 2
            if (preg_match('/HTTP_(.+)/', $h, $hp)) {
60
                $headers[$hp[1]] = $v;
61
            }
62
        }
63 2
        return $headers;
64
    }
65
}
66
67
if (file_exists(CORE_DIR)) {
68
    $loaded_files = [];
69
    //Autoload de módulos
70
    $finder = new Finder();
71
    $finder->files()->in(CORE_DIR)->name('autoload.php');
72
    /* @var $file SplFileInfo */
73
    foreach ($finder as $file) {
74
        $path = $file->getRealPath();
75
        if (!in_array($path, $loaded_files)) {
76
            $loaded_files[] = $path;
77
            require_once($path);
78
        }
79
    }
80
}
81
82
if (!function_exists('t')) {
83
    function t($message, $key = null, $reload = false)
84
    {
85 10
        return CustomTranslateExtension::_($message, $key, $reload);
86
    }
87
}
88