Passed
Push — master ( 488825...f88249 )
by Vladimir
03:10
created

helpers.php ➔ session()   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\Application\Kernel
40
     */
41
    function kernel(): FondBot\Application\Kernel
42
    {
43 6
        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 4
        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 1
        return kernel()->getSession();
71
    }
72
}
73
74 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...
75
    /**
76
     * Get path.
77
     *
78
     * @param string $postfix
79
     *
80
     * @return string
81
     */
82
    function path(string $postfix = null): string
83
    {
84 1
        $path = resolve('base_path');
85
86 1
        if ($postfix === null) {
87 1
            return $path;
88
        }
89
90 1
        return $path.'/'.$postfix;
91
    }
92
}
93
94 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...
95
    /**
96
     * Get resources path.
97
     *
98
     * @param string $postfix
99
     *
100
     * @return string
101
     */
102
    function resources(string $postfix = null): string
103
    {
104 1
        $path = resolve('resources_path');
105
106 1
        if ($postfix === null) {
107 1
            return $path;
108
        }
109
110 1
        return $path.'/'.$postfix;
111
    }
112
}
113
114
if (!function_exists('logger')) {
115
    /**
116
     * Get logger.
117
     *
118
     * @return Monolog\Logger|Psr\Log\LoggerInterface
119
     */
120
    function logger(): Monolog\Logger
121
    {
122 1
        return resolve(Monolog\Logger::class);
123
    }
124
}
125