Skip to content

Commit 215d5fa

Browse files
Added some additional scalar types and return types
1 parent a672653 commit 215d5fa

32 files changed

+121
-117
lines changed

lib/Github/Api/AbstractApi.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Github\Client;
66
use Github\HttpClient\Message\ResponseMediator;
7+
use Psr\Http\Message\ResponseInterface;
78

89
/**
910
* @author Joseph Bielawski <stloyd@gmail.com>
@@ -42,7 +43,7 @@ public function __construct(Client $client)
4243
*
4344
* @return Client
4445
*/
45-
protected function getClient()
46+
protected function getClient(): Client
4647
{
4748
return $this->client;
4849
}
@@ -52,13 +53,17 @@ protected function getClient()
5253
*
5354
* @return string
5455
*/
55-
protected function getApiVersion()
56+
protected function getApiVersion(): string
5657
{
5758
return $this->client->getApiVersion();
5859
}
5960

61+
/**
62+
* @return $this
63+
*/
6064
public function configure()
6165
{
66+
return $this;
6267
}
6368

6469
/**
@@ -70,7 +75,7 @@ public function configure()
7075
*
7176
* @return array|string
7277
*/
73-
protected function get($path, array $parameters = [], array $requestHeaders = [])
78+
protected function get(string $path, array $parameters = [], array $requestHeaders = [])
7479
{
7580
if (null !== $this->perPage && !isset($parameters['per_page'])) {
7681
$parameters['per_page'] = $this->perPage;
@@ -96,9 +101,9 @@ protected function get($path, array $parameters = [], array $requestHeaders = []
96101
* @param array $parameters HEAD parameters.
97102
* @param array $requestHeaders Request headers.
98103
*
99-
* @return \Psr\Http\Message\ResponseInterface
104+
* @return ResponseInterface
100105
*/
101-
protected function head($path, array $parameters = [], array $requestHeaders = [])
106+
protected function head(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
102107
{
103108
if (array_key_exists('ref', $parameters) && null === $parameters['ref']) {
104109
unset($parameters['ref']);
@@ -116,7 +121,7 @@ protected function head($path, array $parameters = [], array $requestHeaders = [
116121
*
117122
* @return array|string
118123
*/
119-
protected function post($path, array $parameters = [], array $requestHeaders = [])
124+
protected function post(string $path, array $parameters = [], array $requestHeaders = [])
120125
{
121126
return $this->postRaw(
122127
$path,
@@ -134,7 +139,7 @@ protected function post($path, array $parameters = [], array $requestHeaders = [
134139
*
135140
* @return array|string
136141
*/
137-
protected function postRaw($path, $body, array $requestHeaders = [])
142+
protected function postRaw(string $path, $body, array $requestHeaders = [])
138143
{
139144
$response = $this->client->getHttpClient()->post(
140145
$path,
@@ -154,7 +159,7 @@ protected function postRaw($path, $body, array $requestHeaders = [])
154159
*
155160
* @return array|string
156161
*/
157-
protected function patch($path, array $parameters = [], array $requestHeaders = [])
162+
protected function patch(string $path, array $parameters = [], array $requestHeaders = [])
158163
{
159164
$response = $this->client->getHttpClient()->patch(
160165
$path,
@@ -174,7 +179,7 @@ protected function patch($path, array $parameters = [], array $requestHeaders =
174179
*
175180
* @return array|string
176181
*/
177-
protected function put($path, array $parameters = [], array $requestHeaders = [])
182+
protected function put(string $path, array $parameters = [], array $requestHeaders = [])
178183
{
179184
$response = $this->client->getHttpClient()->put(
180185
$path,
@@ -194,7 +199,7 @@ protected function put($path, array $parameters = [], array $requestHeaders = []
194199
*
195200
* @return array|string
196201
*/
197-
protected function delete($path, array $parameters = [], array $requestHeaders = [])
202+
protected function delete(string $path, array $parameters = [], array $requestHeaders = [])
198203
{
199204
$response = $this->client->getHttpClient()->delete(
200205
$path,
@@ -212,7 +217,7 @@ protected function delete($path, array $parameters = [], array $requestHeaders =
212217
*
213218
* @return string|null
214219
*/
215-
protected function createJsonBody(array $parameters)
220+
protected function createJsonBody(array $parameters): ?string
216221
{
217222
return (count($parameters) === 0) ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0);
218223
}

lib/Github/Api/AcceptHeaderTrait.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Github\Api;
44

5+
use Psr\Http\Message\ResponseInterface;
6+
57
/**
68
* A trait to make sure we add accept headers on all requests.
79
*
@@ -12,37 +14,37 @@ trait AcceptHeaderTrait
1214
/** @var string */
1315
protected $acceptHeaderValue;
1416

15-
protected function get($path, array $parameters = [], array $requestHeaders = [])
17+
protected function get(string $path, array $parameters = [], array $requestHeaders = [])
1618
{
1719
return parent::get($path, $parameters, $this->mergeHeaders($requestHeaders));
1820
}
1921

20-
protected function head($path, array $parameters = [], array $requestHeaders = [])
22+
protected function head(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
2123
{
2224
return parent::head($path, $parameters, $this->mergeHeaders($requestHeaders));
2325
}
2426

25-
protected function post($path, array $parameters = [], array $requestHeaders = [])
27+
protected function post(string $path, array $parameters = [], array $requestHeaders = [])
2628
{
2729
return parent::post($path, $parameters, $this->mergeHeaders($requestHeaders));
2830
}
2931

30-
protected function postRaw($path, $body, array $requestHeaders = [])
32+
protected function postRaw(string $path, $body, array $requestHeaders = [])
3133
{
3234
return parent::postRaw($path, $body, $this->mergeHeaders($requestHeaders));
3335
}
3436

35-
protected function patch($path, array $parameters = [], array $requestHeaders = [])
37+
protected function patch(string $path, array $parameters = [], array $requestHeaders = [])
3638
{
3739
return parent::patch($path, $parameters, $this->mergeHeaders($requestHeaders));
3840
}
3941

40-
protected function put($path, array $parameters = [], array $requestHeaders = [])
42+
protected function put(string $path, array $parameters = [], array $requestHeaders = [])
4143
{
4244
return parent::put($path, $parameters, $this->mergeHeaders($requestHeaders));
4345
}
4446

45-
protected function delete($path, array $parameters = [], array $requestHeaders = [])
47+
protected function delete(string $path, array $parameters = [], array $requestHeaders = [])
4648
{
4749
return parent::delete($path, $parameters, $this->mergeHeaders($requestHeaders));
4850
}
@@ -52,7 +54,7 @@ protected function delete($path, array $parameters = [], array $requestHeaders =
5254
*
5355
* @return array
5456
*/
55-
private function mergeHeaders(array $headers = [])
57+
private function mergeHeaders(array $headers = []): array
5658
{
5759
$default = [];
5860
if ($this->acceptHeaderValue) {

lib/Github/Api/CurrentUser/Starring.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Starring extends AbstractApi
2121
*
2222
* @param string $bodyType
2323
*
24-
* @return self
24+
* @return $this
2525
*/
2626
public function configure($bodyType = null)
2727
{

lib/Github/Api/Gist/Comments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Comments extends AbstractApi
2121
*
2222
* @param string|null $bodyType
2323
*
24-
* @return self
24+
* @return $this
2525
*/
2626
public function configure($bodyType = null)
2727
{

lib/Github/Api/Gists.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Gists extends AbstractApi
2424
*
2525
* @param string|null $bodyType
2626
*
27-
* @return self
27+
* @return $this
2828
*/
2929
public function configure($bodyType = null)
3030
{

lib/Github/Api/GitData/Blobs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Blobs extends AbstractApi
2121
*
2222
* @param string|null $bodyType
2323
*
24-
* @return self
24+
* @return $this
2525
*/
2626
public function configure($bodyType = null)
2727
{

lib/Github/Api/Issue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Issue extends AbstractApi
2929
*
3030
* @param string|null $bodyType
3131
*
32-
* @return self
32+
* @return $this
3333
*/
3434
public function configure($bodyType = null)
3535
{

lib/Github/Api/Issue/Comments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Comments extends AbstractApi
2323
*
2424
* @param string|null $bodyType
2525
*
26-
* @return self
26+
* @return $this
2727
*/
2828
public function configure($bodyType = null)
2929
{

lib/Github/Api/Project/AbstractProjectApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ abstract class AbstractProjectApi extends AbstractApi
1414
*
1515
* @see https://developer.github.com/v3/repos/projects/#projects
1616
*
17-
* @return self
17+
* @return $this
1818
*/
1919
public function configure()
2020
{

lib/Github/Api/Project/Cards.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Cards extends AbstractApi
1515
*
1616
* @see https://developer.github.com/v3/repos/projects/#projects
1717
*
18-
* @return self
18+
* @return $this
1919
*/
2020
public function configure()
2121
{

lib/Github/Api/PullRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PullRequest extends AbstractApi
2727
* @param string|null $bodyType
2828
* @param string|null $apiVersion
2929
*
30-
* @return self
30+
* @return $this
3131
*/
3232
public function configure($bodyType = null, $apiVersion = null)
3333
{

lib/Github/Api/PullRequest/Comments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Comments extends AbstractApi
2323
* @param string|null $bodyType
2424
* @param string|null $apiVersion
2525
*
26-
* @return self
26+
* @return $this
2727
*/
2828
public function configure($bodyType = null, $apiVersion = null)
2929
{

lib/Github/Api/Repository/Comments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Comments extends AbstractApi
2323
*
2424
* @param string|null $bodyType
2525
*
26-
* @return self
26+
* @return $this
2727
*/
2828
public function configure($bodyType = null)
2929
{

lib/Github/Api/Repository/Contents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Contents extends AbstractApi
2525
*
2626
* @param string|null $bodyType
2727
*
28-
* @return self
28+
* @return $this
2929
*/
3030
public function configure($bodyType = null)
3131
{

lib/Github/Api/Repository/Stargazers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Stargazers extends AbstractApi
2222
*
2323
* @param string $bodyType
2424
*
25-
* @return self
25+
* @return $this
2626
*/
2727
public function configure($bodyType = null)
2828
{

lib/Github/Client.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Http\Discovery\Psr17FactoryDiscovery;
1616
use Psr\Cache\CacheItemPoolInterface;
1717
use Psr\Http\Client\ClientInterface;
18+
use Psr\Http\Message\ResponseInterface;
1819

1920
/**
2021
* Simple yet very cool PHP GitHub client.
@@ -142,7 +143,7 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul
142143
*
143144
* @return Client
144145
*/
145-
public static function createWithHttpClient(ClientInterface $httpClient)
146+
public static function createWithHttpClient(ClientInterface $httpClient): self
146147
{
147148
$builder = new Builder($httpClient);
148149

@@ -156,7 +157,7 @@ public static function createWithHttpClient(ClientInterface $httpClient)
156157
*
157158
* @return AbstractApi
158159
*/
159-
public function api($name)
160+
public function api($name): AbstractApi
160161
{
161162
switch ($name) {
162163
case 'me':
@@ -311,7 +312,7 @@ public function api($name)
311312
*
312313
* @return void
313314
*/
314-
public function authenticate($tokenOrLogin, $password = null, $authMethod = null)
315+
public function authenticate($tokenOrLogin, $password = null, $authMethod = null): void
315316
{
316317
if (null === $authMethod && (self::AUTH_JWT === $password || self::AUTH_ACCESS_TOKEN === $password)) {
317318
$authMethod = $password;
@@ -333,7 +334,7 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null
333334
*
334335
* @return void
335336
*/
336-
private function setEnterpriseUrl($enterpriseUrl)
337+
private function setEnterpriseUrl($enterpriseUrl): void
337338
{
338339
$builder = $this->getHttpClientBuilder();
339340
$builder->removePlugin(Plugin\AddHostPlugin::class);
@@ -346,7 +347,7 @@ private function setEnterpriseUrl($enterpriseUrl)
346347
/**
347348
* @return string
348349
*/
349-
public function getApiVersion()
350+
public function getApiVersion(): string
350351
{
351352
return $this->apiVersion;
352353
}
@@ -359,7 +360,7 @@ public function getApiVersion()
359360
*
360361
* @return void
361362
*/
362-
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
363+
public function addCache(CacheItemPoolInterface $cachePool, array $config = []): void
363364
{
364365
$this->getHttpClientBuilder()->addCache($cachePool, $config);
365366
}
@@ -369,7 +370,7 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
369370
*
370371
* @return void
371372
*/
372-
public function removeCache()
373+
public function removeCache(): void
373374
{
374375
$this->getHttpClientBuilder()->removeCache();
375376
}
@@ -380,7 +381,7 @@ public function removeCache()
380381
*
381382
* @return AbstractApi
382383
*/
383-
public function __call($name, $args)
384+
public function __call($name, $args): AbstractApi
384385
{
385386
try {
386387
return $this->api($name);
@@ -392,23 +393,23 @@ public function __call($name, $args)
392393
/**
393394
* @return null|\Psr\Http\Message\ResponseInterface
394395
*/
395-
public function getLastResponse()
396+
public function getLastResponse(): ?ResponseInterface
396397
{
397398
return $this->responseHistory->getLastResponse();
398399
}
399400

400401
/**
401402
* @return HttpMethodsClientInterface
402403
*/
403-
public function getHttpClient()
404+
public function getHttpClient(): HttpMethodsClientInterface
404405
{
405406
return $this->getHttpClientBuilder()->getHttpClient();
406407
}
407408

408409
/**
409410
* @return Builder
410411
*/
411-
protected function getHttpClientBuilder()
412+
protected function getHttpClientBuilder(): Builder
412413
{
413414
return $this->httpClientBuilder;
414415
}

0 commit comments

Comments
 (0)