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.
Completed
Push — master ( 2f39ea...79b72f )
by Lanre
02:06
created

functions.php ➔ toQueryParams()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 4
nop 1
dl 0
loc 20
ccs 9
cts 9
cp 1
crap 4
rs 9.2
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)
0 ignored issues
show
Coding Style introduced by
env uses the super-global variable $_ENV which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
12
    {
13 27
        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 5
        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 (!$queryParams) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $queryParams of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
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