Skip to content

Commit 8d9c3bf

Browse files
authored
minor #949 [3.x] Added some additional scalar types and return types (GrahamCampbell)
This PR was merged into the 3.0.x-dev branch. Discussion ---------- I've **not** added return types to all the API methods. If that is wanted, it could be followed up with an additional PR, but we'd have to be very confident all the return type phpdoc was correct before making them real return types (indeed, not all the methods in there even have documented return types)! --- Depends on #950. Commits ------- 215d5fa Added some additional scalar types and return types
2 parents a672653 + 215d5fa commit 8d9c3bf

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 <[email protected]>
@@ -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
{

0 commit comments

Comments
 (0)