Completed
Branch master (2d0ab0)
by Adrien
07:23
created

Debug.php ➔ ve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
class Debug
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    /**
6
     * Export variables omitting array keys that are strictly numeric
7
     *
8
     * By default will output result
9
     *
10
     * @param mixed $data
11
     * @param bool $return
12
     * @param int $level
13
     * @return string string representation of variable
14
     */
15
    public static function export($data, bool $return = false, int $level = 0)
16
    {
17
        $result = '';
18
        if (is_array($data)) {
19
            $needKey = array_keys($data) !== range(0, count($data) - 1);
20
            $result .= '[' . PHP_EOL;
21
            foreach ($data as $key => $value) {
22
                $result .= str_repeat(' ', 4 * ($level + 1));
23
                if ($needKey) {
24
                    $result .= self::export($key, true, $level + 1);
25
                    $result .= ' => ';
26
                }
27
28
                $result .= self::export($value, true, $level + 1);
29
                $result .= ',' . PHP_EOL;
30
            }
31
            $result .= str_repeat(' ', 4 * $level) . ']';
32
        } else {
33
            $result .= var_export($data, true);
34
        }
35
36
        if (!$return) {
37
            echo $result;
38
        }
39
40
        return $result;
41
    }
42
}
43
44
function ve($a, bool $return = false)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Coding Style introduced by
This method's name is shorter than the configured minimum length of 4 characters.

Even though PHP does not care about the name of your methods, it is generally a good practice to choose method names which can be easily understood by other human readers.

Loading history...
45
{
46
    return Debug::export($a, $return);
47
}
48
49
function v()
0 ignored issues
show
Coding Style introduced by
This method's name is shorter than the configured minimum length of 4 characters.

Even though PHP does not care about the name of your methods, it is generally a good practice to choose method names which can be easily understood by other human readers.

Loading history...
50
{
51
    var_dump(func_get_args());
0 ignored issues
show
Security Debugging Code introduced by
var_dump(func_get_args()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
52
}
53
54
function w()
0 ignored issues
show
Coding Style introduced by
This method's name is shorter than the configured minimum length of 4 characters.

Even though PHP does not care about the name of your methods, it is generally a good practice to choose method names which can be easily understood by other human readers.

Loading history...
55
{
56
    $isHtml = (PHP_SAPI !== 'cli');
57
    echo "\n_________________________________________________________________________________________________________________________" . ($isHtml ? '</br>' : '') . "\n";
58
    var_dump(func_get_args());
0 ignored issues
show
Security Debugging Code introduced by
var_dump(func_get_args()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
59
    echo "\n" . ($isHtml ? '</br>' : '') . '_________________________________________________________________________________________________________________________' . ($isHtml ? '<pre>' : '') . "\n";
60
    debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
61
    echo '' . ($isHtml ? '</pre>' : '') . '_________________________________________________________________________________________________________________________' . ($isHtml ? '</br>' : '') . "\n";
62
    die("script aborted on purpose.\n");
0 ignored issues
show
Coding Style Compatibility introduced by
The function w() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
63
}
64