Passed
Push — master ( 236a58...055c31 )
by Vladimir
07:58
created

helpers.php ➔ context()   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
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\Foundation\Kernel
40
     */
41
    function kernel(): \FondBot\Foundation\Kernel
42
    {
43 29
        return FondBot\Foundation\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 24
        return kernel()->resolve($alias, $args);
59
    }
60
}
61
62
if (!function_exists('session')) {
63
    /**
64
     * Get session.
65
     *
66
     * @return FondBot\Conversation\Session
67
     */
68
    function session(): FondBot\Conversation\Session
69
    {
70 2
        return kernel()->getSession();
71
    }
72
}
73
74
if (!function_exists('context')) {
75
    /**
76
     * Get context.
77
     *
78
     * @return FondBot\Conversation\Context
79
     */
80
    function context(): FondBot\Conversation\Context
81
    {
82 2
        return kernel()->getContext();
83
    }
84
}
85
86 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...
87
    /**
88
     * Get path.
89
     *
90
     * @param string $postfix
91
     *
92
     * @return string
93
     */
94
    function path(string $postfix = null): string
95
    {
96 1
        $path = resolve('base_path');
97
98 1
        if ($postfix === null) {
99 1
            return $path;
100
        }
101
102 1
        return $path.'/'.$postfix;
103
    }
104
}
105
106 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...
107
    /**
108
     * Get resources path.
109
     *
110
     * @param string $postfix
111
     *
112
     * @return string
113
     */
114
    function resources(string $postfix = null): string
115
    {
116 1
        $path = resolve('resources_path');
117
118 1
        if ($postfix === null) {
119 1
            return $path;
120
        }
121
122 1
        return $path.'/'.$postfix;
123
    }
124
}
125
126
if (!function_exists('logger')) {
127
    /**
128
     * Get logger.
129
     *
130
     * @return Monolog\Logger|Psr\Log\LoggerInterface
131
     */
132
    function logger(): Monolog\Logger
133
    {
134 1
        return resolve(Monolog\Logger::class);
135
    }
136
}
137