Skip to content

Commit 9ef6c24

Browse files
Query builder type safety
1 parent 78671a5 commit 9ef6c24

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/Gitlab/HttpClient/Message/QueryStringBuilder.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,37 @@ final class QueryStringBuilder
1515
public static function build($query)
1616
{
1717
if (!is_array($query)) {
18-
return static::rawurlencode($query);
18+
return self::rawurlencode($query);
1919
}
2020
$query = array_filter($query, function ($value) {
21-
return (null !== $value);
21+
return null !== $value;
2222
});
2323

2424
return implode('&', array_map(function ($value, $key) {
25-
return static::encode($value, $key);
25+
return self::encode($value, $key);
2626
}, $query, array_keys($query)));
2727
}
2828

2929
/**
30-
* Encode a value
31-
* @param mixed $query
30+
* Encode a value.
31+
*
32+
* @param mixed $query
3233
* @param string $prefix
3334
*
3435
* @return string
3536
*/
3637
private static function encode($query, $prefix)
3738
{
3839
if (!is_array($query)) {
39-
return static::rawurlencode($prefix).'='.static::rawurlencode($query);
40+
return self::rawurlencode($prefix).'='.self::rawurlencode($query);
4041
}
4142

42-
$isIndexedArray = static::isIndexedArray($query);
43+
$isIndexedArray = self::isIndexedArray($query);
44+
4345
return implode('&', array_map(function ($value, $key) use ($prefix, $isIndexedArray) {
4446
$prefix = $isIndexedArray ? $prefix.'[]' : $prefix.'['.$key.']';
45-
return static::encode($value, $prefix);
47+
48+
return self::encode($value, $prefix);
4649
}, $query, array_keys($query)));
4750
}
4851

@@ -71,10 +74,10 @@ public static function isIndexedArray(array $query)
7174
*/
7275
private static function rawurlencode($value)
7376
{
74-
if ($value === false) {
77+
if (false === $value) {
7578
return '0';
7679
}
7780

78-
return rawurlencode($value);
81+
return rawurlencode((string) $value);
7982
}
8083
}

0 commit comments

Comments
 (0)