GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

functions.php ➔ toQueryParams()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 20
ccs 9
cts 9
cp 1
crap 4
rs 9.6
c 0
b 0
f 0
1
<?php
2
3
namespace Gbowo;
4
5
if (!function_exists("Gbowo\\env")) {
6
    /**
7
     * * Load a value from `$_ENV`.
8
     * @param string $value
9
     * @return mixed
10
     */
11
    function env(string $value)
12
    {
13 25
        return $_ENV[$value];
14
    }
15
}
16
17
if (!function_exists("Gbowo\\generateTransRef")) {
18
    /**
19
     * Generate a cryptographically secure random string
20
     * @param int $length Defaults to 10
21
     * @return string
22
     */
23
    function generateTransRef(int $length = 10)
24
    {
25 6
        return bin2hex(random_bytes($length));
26
    }
27
}
28
29
if (!function_exists("Gbowo\\toKobo")) {
30
    /**
31
     * Convert a given amount to it's kobo equivalent.
32
     * This is just an helper function and you def' can do without it
33
     * @param  $amount
34
     * @return float
35
     */
36
    function toKobo($amount)
37
    {
38 2
        return $amount * 100;
39
    }
40
}
41
42
if (!function_exists("Gbowo\\toQueryParams")) {
43
    /**
44
     * Converts a dictionary into HTTP query parameter(s) which can then be attached to a link
45
     * ["name" => "Lanre", "hobby" => "Trolling"] gets formatted as ?name=lanre&hobby=trolling
46
     * @param  array $queryParams The dictionary to be converted
47
     * @return string A string that represents a "key-value" url query formed from a dictionary
48
     */
49
    function toQueryParams(array $queryParams = []) : string
50
    {
51 3
        $params = "";
52
53 3
        if (count($queryParams) == 0) {
54 1
            return $params;
55
        }
56
57 2
        foreach ($queryParams as $key => $value) {
58 2
            $encodedValue = urlencode($value);
59
60 2
            if (reset($queryParams) == $value) {
61 2
                $params .= "?{$key}={$encodedValue}";
62
            } else {
63 2
                $params .= "&{$key}={$encodedValue}";
64
            }
65
        }
66
67 2
        return $params;
68
    }
69
}
70