Passed
Pull Request — master (#21)
by Maximo
04:23
created

paymentGatewayIsActive()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Gewaer\Core;
4
5
use function function_exists;
6
use function getenv;
7
8 2
if (true !== function_exists('Gewaer\Core\appPath')) {
9
    /**
10
     * Get the application path.
11
     *
12
     * @param  string $path
13
     *
14
     * @return string
15
     */
16
    function appPath(string $path = ''): string
17
    {
18 52
        return dirname(dirname(__DIR__)) . ($path ? DIRECTORY_SEPARATOR . $path : $path);
19
    }
20
}
21
22 2
if (true !== function_exists('Gewaer\Core\envValue')) {
23
    /**
24
     * Gets a variable from the environment, returns it properly formatted or the
25
     * default if it does not exist
26
     *
27
     * @param string     $variable
28
     * @param mixed|null $default
29
     *
30
     * @return mixed
31
     */
32
    function envValue(string $variable, $default = null)
33
    {
34 53
        $return = $default;
35 53
        $value = getenv($variable);
36
        $values = [
37 53
            'false' => false,
38
            'true' => true,
39
            'null' => null,
40
        ];
41
42 53
        if (false !== $value) {
43 53
            $return = $values[$value] ?? $value;
44
        }
45
46 53
        return $return;
47
    }
48
}
49
50 2
if (true !== function_exists('Gewaer\Core\appUrl')) {
51
    /**
52
     * Constructs a URL for links with resource and id
53
     *
54
     * @param string $resource
55
     * @param int    $recordId
56
     *
57
     * @return array|false|mixed|string
58
     */
59
    function appUrl(string $resource, int $recordId)
60
    {
61
        return sprintf(
62
            '%s/%s/%s',
63
            envValue('APP_URL'),
64
            $resource,
65
            $recordId
66
        );
67
    }
68
}
69
70 2
if (true !== function_exists('Gewaer\Core\paymentGatewayIsActive')) {
71
    /**
72
     * Do we have a payment metho actived on the app?
73
     *
74
     * @return boolean
75
     */
76
    function paymentGatewayIsActive(): bool
77
    {
78 1
        return !empty(getenv('STRIPE_SECRET')) ? true : false;
79
    }
80
}
81