Passed
Push — master ( 6d232f...71788a )
by Vladimir
02:31
created

helpers.php ➔ kernel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
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 3
        if ($value === null) {
18 1
            return $default;
19
        }
20 3
        switch (mb_strtolower($value)) {
21 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...
22 1
                return true;
23 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...
24 1
                return false;
25 3
            case 'null':
26 1
                return null;
27
        }
28
29 3
        return $value;
30
    }
31
}
32
33
if (!function_exists('kernel')) {
34
    /**
35
     * Get kernel instance.
36
     *
37
     * @return \FondBot\Foundation\Kernel
38
     */
39
    function kernel(): \FondBot\Foundation\Kernel
40
    {
41 33
        return FondBot\Foundation\Kernel::getInstance();
42
    }
43
}
44
45
if (!function_exists('resolve')) {
46
    /**
47
     * Resolve an alias from container.
48
     *
49
     * @param string $alias
50
     * @param array  $args
51
     *
52
     * @return mixed
53
     */
54
    function resolve(string $alias, array $args = [])
55
    {
56 28
        return kernel()->resolve($alias, $args);
57
    }
58
}
59
60
if (!function_exists('session')) {
61
    /**
62
     * Get session.
63
     *
64
     * @return FondBot\Conversation\Session
65
     */
66
    function session(): FondBot\Conversation\Session
67
    {
68 2
        return kernel()->getSession();
69
    }
70
}
71
72
if (!function_exists('context')) {
73
    /**
74
     * Get context.
75
     *
76
     * @return FondBot\Conversation\Context
77
     */
78
    function context(): FondBot\Conversation\Context
79
    {
80 2
        return kernel()->getContext();
81
    }
82
}
83
84 View Code Duplication
if (!function_exists('path')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
    /**
86
     * Get path.
87
     *
88
     * @param string $postfix
89
     *
90
     * @return string
91
     */
92
    function path(string $postfix = null): string
93
    {
94 1
        $path = resolve('base_path');
95
96 1
        if ($postfix === null) {
97 1
            return $path;
98
        }
99
100 1
        return $path.'/'.$postfix;
101
    }
102
}
103
104 View Code Duplication
if (!function_exists('resources')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
    /**
106
     * Get resources path.
107
     *
108
     * @param string $postfix
109
     *
110
     * @return string
111
     */
112
    function resources(string $postfix = null): string
113
    {
114 1
        $path = resolve('resources_path');
115
116 1
        if ($postfix === null) {
117 1
            return $path;
118
        }
119
120 1
        return $path.'/'.$postfix;
121
    }
122
}
123
124
if (!function_exists('logger')) {
125
    /**
126
     * Get logger.
127
     *
128
     * @return Monolog\Logger|Psr\Log\LoggerInterface
129
     */
130
    function logger(): Monolog\Logger
131
    {
132 1
        return resolve(Monolog\Logger::class);
133
    }
134
}
135