Skip to content

Commit 6dd3410

Browse files
Merge branch '9.18' into 9.19
2 parents 121c1bc + d938a67 commit 6dd3410

File tree

11 files changed

+135
-51
lines changed

11 files changed

+135
-51
lines changed

lib/Gitlab/Api/AbstractApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Gitlab\Client;
66
use Gitlab\Exception\RuntimeException;
7-
use Gitlab\HttpClient\Message\QueryStringBuilder;
87
use Gitlab\HttpClient\Message\ResponseMediator;
8+
use Gitlab\HttpClient\Util\QueryStringBuilder;
99
use Http\Discovery\StreamFactoryDiscovery;
1010
use Http\Message\MultipartStream\MultipartStreamBuilder;
1111
use Http\Message\StreamFactory;

lib/Gitlab/HttpClient/Message/QueryStringBuilder.php

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Gitlab\HttpClient\Message;
44

5+
use Gitlab\HttpClient\Util\QueryStringBuilder as UtilQueryStringBuilder;
6+
7+
/**
8+
* @deprecated since 9.18 and will be removed in 10.0.
9+
*/
510
final class QueryStringBuilder
611
{
712
/**
@@ -11,42 +16,14 @@ final class QueryStringBuilder
1116
* @param mixed $query
1217
*
1318
* @return string
19+
*
20+
* @deprecated since 9.18 and will be removed in 10.0.
1421
*/
1522
public static function build($query)
1623
{
17-
if (!is_array($query)) {
18-
return self::rawurlencode($query);
19-
}
20-
$query = array_filter($query, function ($value) {
21-
return null !== $value;
22-
});
24+
@trigger_error(sprintf('The %s() method is deprecated since version 9.18 and will be removed in 10.0.', __METHOD__), E_USER_DEPRECATED);
2325

24-
return implode('&', array_map(function ($value, $key) {
25-
return self::encode($value, $key);
26-
}, $query, array_keys($query)));
27-
}
28-
29-
/**
30-
* Encode a value.
31-
*
32-
* @param mixed $query
33-
* @param string $prefix
34-
*
35-
* @return string
36-
*/
37-
private static function encode($query, $prefix)
38-
{
39-
if (!is_array($query)) {
40-
return self::rawurlencode($prefix).'='.self::rawurlencode($query);
41-
}
42-
43-
$isIndexedArray = self::isIndexedArray($query);
44-
45-
return implode('&', array_map(function ($value, $key) use ($prefix, $isIndexedArray) {
46-
$prefix = $isIndexedArray ? $prefix.'[]' : $prefix.'['.$key.']';
47-
48-
return self::encode($value, $prefix);
49-
}, $query, array_keys($query)));
26+
return UtilQueryStringBuilder::build($query);
5027
}
5128

5229
/**
@@ -55,29 +32,17 @@ private static function encode($query, $prefix)
5532
* @param array $query
5633
*
5734
* @return bool
35+
*
36+
* @deprecated since 9.18 and will be removed in 10.0.
5837
*/
5938
public static function isIndexedArray(array $query)
6039
{
40+
@trigger_error(sprintf('The %s() method is deprecated since version 9.18 and will be removed in 10.0.', __METHOD__), E_USER_DEPRECATED);
41+
6142
if (0 === count($query) || !isset($query[0])) {
6243
return false;
6344
}
6445

6546
return array_keys($query) === range(0, count($query) - 1);
6647
}
67-
68-
/**
69-
* Encode a value like rawurlencode, but return "0" when false is given.
70-
*
71-
* @param mixed $value
72-
*
73-
* @return string
74-
*/
75-
private static function rawurlencode($value)
76-
{
77-
if (false === $value) {
78-
return '0';
79-
}
80-
81-
return rawurlencode((string) $value);
82-
}
8348
}

lib/Gitlab/HttpClient/Plugin/ApiVersion.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
/**
1111
* Prefix requests path with /api/v4/ if required.
1212
*
13+
* @internal
14+
*
1315
* @final
1416
*
1517
* @author Fabien Bourigault <[email protected]>

lib/Gitlab/HttpClient/Plugin/Authentication.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
/**
1111
* Add authentication to the request.
1212
*
13+
* @internal
14+
*
1315
* @final
1416
*
1517
* @author Tobias Nyholm <[email protected]>

lib/Gitlab/HttpClient/Plugin/GitlabExceptionThrower.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
/**
1616
* A plugin to remember the last response.
1717
*
18+
* @internal
19+
*
1820
* @final
1921
*
2022
* @author Tobias Nyholm <[email protected]>

lib/Gitlab/HttpClient/Plugin/History.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/**
1010
* A plugin to remember the last response.
1111
*
12+
* @internal
13+
*
1214
* @final
1315
*
1416
* @author Tobias Nyholm <[email protected]>

lib/Gitlab/HttpClient/Plugin/HistoryTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Psr\Http\Message\RequestInterface;
99

1010
if (interface_exists(HttpMethodsClientInterface::class)) {
11+
/**
12+
* @internal
13+
*/
1114
trait HistoryTrait
1215
{
1316
/**
@@ -23,6 +26,9 @@ public function addFailure(RequestInterface $request, ClientExceptionInterface $
2326
}
2427
}
2528
} else {
29+
/**
30+
* @internal
31+
*/
2632
trait HistoryTrait
2733
{
2834
/**
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace Gitlab\HttpClient\Util;
4+
5+
/**
6+
* @internal
7+
*/
8+
final class QueryStringBuilder
9+
{
10+
/**
11+
* Encode a query as a query string according to RFC 3986.
12+
*
13+
* Indexed arrays are encoded using empty squared brackets ([]) unlike
14+
* `http_build_query`.
15+
*
16+
* @param mixed $query
17+
*
18+
* @return string
19+
*/
20+
public static function build($query)
21+
{
22+
if (!is_array($query)) {
23+
return self::rawurlencode($query);
24+
}
25+
$query = array_filter($query, function ($value) {
26+
return null !== $value;
27+
});
28+
29+
return implode('&', array_map(function ($value, $key) {
30+
return self::encode($value, $key);
31+
}, $query, array_keys($query)));
32+
}
33+
34+
/**
35+
* Encode a value.
36+
*
37+
* @param mixed $query
38+
* @param string $prefix
39+
*
40+
* @return string
41+
*/
42+
private static function encode($query, $prefix)
43+
{
44+
if (!is_array($query)) {
45+
return self::rawurlencode($prefix).'='.self::rawurlencode($query);
46+
}
47+
48+
$isList = self::isList($query);
49+
50+
return implode('&', array_map(function ($value, $key) use ($prefix, $isList) {
51+
$prefix = $isList ? $prefix.'[]' : $prefix.'['.$key.']';
52+
53+
return self::encode($value, $prefix);
54+
}, $query, array_keys($query)));
55+
}
56+
57+
/**
58+
* Tell if the given array is a list.
59+
*
60+
* @param array $query
61+
*
62+
* @return bool
63+
*/
64+
private static function isList(array $query)
65+
{
66+
if (0 === count($query) || !isset($query[0])) {
67+
return false;
68+
}
69+
70+
return array_keys($query) === range(0, count($query) - 1);
71+
}
72+
73+
/**
74+
* Encode a value like rawurlencode, but return "0" when false is given.
75+
*
76+
* @param mixed $value
77+
*
78+
* @return string
79+
*/
80+
private static function rawurlencode($value)
81+
{
82+
if (false === $value) {
83+
return '0';
84+
}
85+
86+
return rawurlencode((string) $value);
87+
}
88+
}

lib/Gitlab/ResultPager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/**
1010
* This is the result pager class.
1111
*
12+
* @final
13+
*
1214
* @author Ramon de la Fuente <[email protected]>
1315
* @author Mitchel Verschoof <[email protected]>
1416
* @author Graham Campbell <[email protected]>

phpstan-baseline.neon

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,18 @@ parameters:
6565
count: 1
6666
path: lib/Gitlab/ResultPager.php
6767

68+
-
69+
message: "#^Method Gitlab\\\\ResultPager\\:\\:postFetch\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
70+
count: 1
71+
path: lib/Gitlab/ResultPager.php
72+
73+
-
74+
message: "#^Method Gitlab\\\\ResultPager\\:\\:has\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
75+
count: 1
76+
path: lib/Gitlab/ResultPager.php
77+
78+
-
79+
message: "#^Method Gitlab\\\\ResultPager\\:\\:get\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
80+
count: 1
81+
path: lib/Gitlab/ResultPager.php
82+

0 commit comments

Comments
 (0)