Skip to content

Commit 9a67acf

Browse files
Added additional return type enforcement
1 parent 496ec45 commit 9a67acf

16 files changed

+104
-98
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
* Updated to latest labels API
1313
* Made builder class final
1414
* Re-worked pagination
15+
* Client authenticate and setUrl now return void
16+
* Added additional return type enforcement
1517

1618
[11.0.0-RC1]: https://github.com/GitLabPHP/Client/compare/10.4.0...11.0.0-RC1
1719

src/Api/AbstractApi.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Gitlab\HttpClient\Util\JsonArray;
2121
use Gitlab\HttpClient\Util\QueryStringBuilder;
2222
use Http\Message\MultipartStream\MultipartStreamBuilder;
23+
use Psr\Http\Message\ResponseInterface;
2324
use Psr\Http\Message\StreamInterface;
2425
use Symfony\Component\OptionsResolver\OptionsResolver;
2526

@@ -74,7 +75,7 @@ public function __construct(Client $client)
7475
*
7576
* @return \Psr\Http\Message\ResponseInterface
7677
*/
77-
protected function getAsResponse(string $uri, array $params = [], array $headers = [])
78+
protected function getAsResponse(string $uri, array $params = [], array $headers = []): ResponseInterface
7879
{
7980
if (null !== $this->perPage && !isset($params['per_page'])) {
8081
$params['per_page'] = $this->perPage;
@@ -176,7 +177,7 @@ protected function delete(string $uri, array $params = [], array $headers = [])
176177
*
177178
* @return string
178179
*/
179-
protected static function encodePath($uri)
180+
protected static function encodePath($uri): string
180181
{
181182
return \rawurlencode((string) $uri);
182183
}
@@ -187,7 +188,7 @@ protected static function encodePath($uri)
187188
*
188189
* @return string
189190
*/
190-
protected function getProjectPath($id, string $uri)
191+
protected function getProjectPath($id, string $uri): string
191192
{
192193
return 'projects/'.self::encodePath($id).'/'.$uri;
193194
}
@@ -197,18 +198,18 @@ protected function getProjectPath($id, string $uri)
197198
*
198199
* @return OptionsResolver
199200
*/
200-
protected function createOptionsResolver()
201+
protected function createOptionsResolver(): OptionsResolver
201202
{
202203
$resolver = new OptionsResolver();
203204
$resolver->setDefined('page')
204205
->setAllowedTypes('page', 'int')
205-
->setAllowedValues('page', function ($value) {
206+
->setAllowedValues('page', function ($value): bool {
206207
return $value > 0;
207208
})
208209
;
209210
$resolver->setDefined('per_page')
210211
->setAllowedTypes('per_page', 'int')
211-
->setAllowedValues('per_page', function ($value) {
212+
->setAllowedValues('per_page', function ($value): bool {
212213
return $value > 0 && $value <= 100;
213214
})
214215
;
@@ -224,7 +225,7 @@ protected function createOptionsResolver()
224225
*
225226
* @return string
226227
*/
227-
private static function prepareUri(string $uri, array $query = [])
228+
private static function prepareUri(string $uri, array $query = []): string
228229
{
229230
$query = \array_filter($query, function ($value): bool {
230231
return null !== $value;
@@ -241,7 +242,7 @@ private static function prepareUri(string $uri, array $query = [])
241242
*
242243
* @return MultipartStreamBuilder
243244
*/
244-
private function createMultipartStreamBuilder(array $params = [], array $files = [])
245+
private function createMultipartStreamBuilder(array $params = [], array $files = []): MultipartStreamBuilder
245246
{
246247
$builder = new MultipartStreamBuilder($this->client->getStreamFactory());
247248

@@ -268,7 +269,7 @@ private function createMultipartStreamBuilder(array $params = [], array $files =
268269
*
269270
* @return StreamInterface
270271
*/
271-
private static function prepareMultipartBody(MultipartStreamBuilder $builder)
272+
private static function prepareMultipartBody(MultipartStreamBuilder $builder): StreamInterface
272273
{
273274
return $builder->build();
274275
}
@@ -281,7 +282,7 @@ private static function prepareMultipartBody(MultipartStreamBuilder $builder)
281282
*
282283
* @return array<string,string>
283284
*/
284-
private static function addMultipartContentType(array $headers, MultipartStreamBuilder $builder)
285+
private static function addMultipartContentType(array $headers, MultipartStreamBuilder $builder): array
285286
{
286287
$contentType = \sprintf('%s; boundary=%s', ResponseMediator::MULTIPART_CONTENT_TYPE, $builder->getBoundary());
287288

@@ -295,7 +296,7 @@ private static function addMultipartContentType(array $headers, MultipartStreamB
295296
*
296297
* @return string|null
297298
*/
298-
private static function prepareJsonBody(array $params)
299+
private static function prepareJsonBody(array $params): ?string
299300
{
300301
$params = \array_filter($params, function ($value): bool {
301302
return null !== $value;
@@ -315,7 +316,7 @@ private static function prepareJsonBody(array $params)
315316
*
316317
* @return array<string,string>
317318
*/
318-
private static function addJsonContentType(array $headers)
319+
private static function addJsonContentType(array $headers): array
319320
{
320321
return \array_merge([ResponseMediator::CONTENT_TYPE_HEADER => ResponseMediator::JSON_CONTENT_TYPE], $headers);
321322
}
@@ -365,7 +366,7 @@ private static function tryFopen(string $filename, string $mode)
365366
*
366367
* @return string
367368
*/
368-
private static function guessFileContentType(string $file)
369+
private static function guessFileContentType(string $file): string
369370
{
370371
if (!\class_exists(\finfo::class, false)) {
371372
return ResponseMediator::STREAM_CONTENT_TYPE;

src/Api/Issues.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Gitlab\Api;
1616

1717
use Symfony\Component\OptionsResolver\Options;
18+
use Symfony\Component\OptionsResolver\OptionsResolver;
1819

1920
class Issues extends AbstractApi
2021
{
@@ -426,9 +427,9 @@ public function showParticipants($project_id, int $issue_iid)
426427
}
427428

428429
/**
429-
* {@inheritdoc}
430+
* @return OptionsResolver
430431
*/
431-
protected function createOptionsResolver()
432+
protected function createOptionsResolver(): OptionsResolver
432433
{
433434
$resolver = parent::createOptionsResolver();
434435
$booleanNormalizer = function (Options $resolver, $value) {

src/Api/IssuesStatistics.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function group($group_id, array $parameters)
5454
/**
5555
* @return OptionsResolver
5656
*/
57-
protected function createOptionsResolver()
57+
protected function createOptionsResolver(): OptionsResolver
5858
{
5959
$resolver = new OptionsResolver();
6060

src/Api/Jobs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ public function play($project_id, int $job_id)
236236
}
237237

238238
/**
239-
* {@inheritdoc}
239+
* @return OptionsResolver
240240
*/
241-
protected function createOptionsResolver()
241+
protected function createOptionsResolver(): OptionsResolver
242242
{
243243
$allowedScopeValues = [
244244
self::SCOPE_CANCELED,

src/Api/Repositories.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,10 @@ public function cherryPick($project_id, string $sha, array $params = [])
484484
return $this->post($this->getProjectPath($project_id, 'repository/commits/'.self::encodePath($sha).'/cherry_pick'), $params);
485485
}
486486

487-
protected function createOptionsResolver()
487+
/**
488+
* @return OptionsResolver
489+
*/
490+
protected function createOptionsResolver(): OptionsResolver
488491
{
489492
$allowedTypeValues = [
490493
self::TYPE_BRANCH,

0 commit comments

Comments
 (0)