Completed
Push — master ( 4bd921...074db3 )
by Vladimir
15:25 queued 08:35
created

helpers.php ➔ path()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
if (!function_exists('env')) {
6
    /**
7
     * Get environment variable value.
8
     *
9
     * @param string $key
10
     * @param null   $default
11
     *
12
     * @return mixed
13
     */
14
    function env(string $key, $default = null)
15
    {
16 3
        $value = $_ENV[$key] ?? null;
17
18 3
        if ($value === null) {
19 1
            return $default;
20
        }
21
22 3
        switch (mb_strtolower($value)) {
23 3
            case 'true':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
24 1
                return true;
25 3
            case 'false':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
26 1
                return false;
27 3
            case 'null':
28 1
                return null;
29
        }
30
31 3
        return $value;
32
    }
33
}
34
35
if (!function_exists('kernel')) {
36
    /**
37
     * Get kernel instance.
38
     *
39
     * @return FondBot\Application\Kernel
40
     */
41
    function kernel(): FondBot\Application\Kernel
42
    {
43 4
        return FondBot\Application\Kernel::getInstance();
44
    }
45
}
46
47
if (!function_exists('resolve')) {
48
    /**
49
     * Resolve an alias from container.
50
     *
51
     * @param string $alias
52
     * @param array  $args
53
     *
54
     * @return mixed
55
     */
56
    function resolve(string $alias, array $args = [])
57
    {
58 3
        return kernel()->resolve($alias, $args);
59
    }
60
}
61
62
if (!function_exists('path')) {
63
    /**
64
     * Get path.
65
     *
66
     * @param string $postfix
67
     *
68
     * @return string
69
     */
70
    function path(string $postfix = null): string
71
    {
72 1
        $basePath = resolve('base_path');
73
74 1
        if ($postfix === null) {
75 1
            return $basePath;
76
        }
77
78 1
        return $basePath.'/'.$postfix;
79
    }
80
}
81
82
if (!function_exists('logger')) {
83
    /**
84
     * Get logger.
85
     *
86
     * @return Monolog\Logger|\Psr\Log\LoggerInterface
87
     */
88
    function logger(): Monolog\Logger
89
    {
90 1
        return resolve(Monolog\Logger::class);
91
    }
92
}
93