helpers.php ➔ env()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Dump and die.
5
 */
6
if (!function_exists('dd')) {
7
    function dd()
0 ignored issues
show
Coding Style introduced by
This method's name is shorter than the configured minimum length of 3 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...
8
    {
9
        $args = func_get_args();
10
        foreach ($args as $arg) {
11
            var_dump($arg);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($arg); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
12
        }
13
        exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function dd() 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...
14
    }
15
}
16
17
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
18
 * Print and die
19
 */
20
if (!function_exists('pd')) {
21
    function pd()
0 ignored issues
show
Coding Style introduced by
This method's name is shorter than the configured minimum length of 3 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...
22
    {
23
        $args = func_get_args();
24
        foreach ($args as $arg) {
25
            print_r($arg);
26
        }
27
        exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function pd() 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...
28
    }
29
}
30
31
/*
32
 * Dump and return
33
 */
34
if (!function_exists('dr')) {
35
    function dr()
0 ignored issues
show
Coding Style introduced by
This method's name is shorter than the configured minimum length of 3 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...
36
    {
37
        $args = func_get_args();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
38
        $result = '';
39
        foreach ($args as $arg) {
40
            $result = '';
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
41
            $type = gettype($arg);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42
            if ($type == 'object') {
43
                $type = get_class($arg);
44
            }
45
            if ($type == 'boolean') {
46
                $result = $arg ? 'true' : 'false';
47
            } else {
48
                $result = print_r($arg, true);
49
            }
50
            $result = sprintf('(%s) %s', $type, $result);
51
        }
52
53
        return $result;
54
    }
55
}
56
57
/*
58
 * Get Enviorment variable
59
 */
60
if (!function_exists('env')) {
61
    function env($key, $defaultValue = '')
62
    {
63
        $env = getenv($key);
64
        if (!$env) {
65
            return $defaultValue;
66
        }
67
68
        return $env;
69
    }
70
}
71