Failed Conditions
Push — master ( 7bc298...ac263b )
by Maximo
20s queued 11s
created

functions.php ➔ paymentGatewayIsActive()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 4
ccs 0
cts 1
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Canvas\Core;
4
5
use function function_exists;
6
use function getenv;
7
8 2
if (!function_exists('Canvas\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 15
        $currentDir = dirname(dirname(getcwd())) . ($path ? DIRECTORY_SEPARATOR . $path : $path);
19
20
        /**
21
         * since we are calling this file from the diferent path we have to verify if its cli.
22
         * @todo look for a better solution , hate this
23
         */
24 15
        if (php_sapi_name() == 'cli') {
25 15
            $currentDir = getcwd() . DIRECTORY_SEPARATOR. $path;
26
        }
27
28 15
        return $currentDir;
29
    }
30
}
31
32 2
if (!function_exists('Canvas\Core\envValue')) {
33
    /**
34
     * Gets a variable from the environment, returns it properly formatted or the
35
     * default if it does not exist.
36
     *
37
     * @param string     $variable
38
     * @param mixed|null $default
39
     *
40
     * @return mixed
41
     */
42
    function envValue(string $variable, $default = null)
43
    {
44 16
        $return = $default;
45 16
        $value = getenv($variable);
46
        $values = [
47 16
            'false' => false,
48
            'true' => true,
49
            'null' => null,
50
        ];
51
52 16
        if (false !== $value) {
53 16
            $return = $values[$value] ?? $value;
54
        }
55
56 16
        return $return;
57
    }
58
}
59
60 2
if (!function_exists('Canvas\Core\appUrl')) {
61
    /**
62
     * Constructs a URL for links with resource and id.
63
     *
64
     * @param string $resource
65
     * @param int    $recordId
66
     *
67
     * @return array|false|mixed|string
68
     */
69
    function appUrl(string $resource, int $recordId)
70
    {
71
        return sprintf(
72
            '%s/%s/%s',
73
            envValue('APP_URL'),
74
            $resource,
75
            $recordId
76
        );
77
    }
78
}
79
80 2
if (!function_exists('Canvas\Core\paymentGatewayIsActive')) {
81
    /**
82
     * Do we have a payment metho actived on the app?
83
     *
84
     * @return boolean
85
     */
86
    function paymentGatewayIsActive(): bool
87
    {
88
        return !empty(getenv('STRIPE_SECRET')) ? true : false;
89
    }
90
}
91
92 2
if (!function_exists('Canvas\Core\isJson')) {
93
    /**
94
     * Given a string determine if its a json.
95
     *
96
     * @param string $string
97
     * @return boolean
98
     */
99
    function isJson(string $string): bool
100
    {
101
        json_decode($string);
102
        return (bool ) (json_last_error() == JSON_ERROR_NONE);
103
    }
104
}
105
106 2
if (!function_exists('Canvas\Core\isSwooleServer')) {
107
    /**
108
     * Are we running a Swoole Server for this app?
109
     *
110
     * @return boolean
111
     */
112
    function isSwooleServer(): bool
113
    {
114 1
        return defined('ENGINE') && ENGINE === 'SWOOLE' ? true : false;
0 ignored issues
show
Bug introduced by
The constant Canvas\Core\ENGINE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
115
    }
116
}
117