Conditions | 4 |
Paths | 4 |
Total Lines | 20 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
49 | function toQueryParams(array $queryParams = []) : string |
||
50 | { |
||
51 | 3 | $params = ""; |
|
52 | |||
53 | 3 | if (!$queryParams) { |
|
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 |
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: