Skip to content

[3.x] Added some additional scalar types and return types #949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions lib/Github/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Github\Client;
use Github\HttpClient\Message\ResponseMediator;
use Psr\Http\Message\ResponseInterface;

/**
* @author Joseph Bielawski <stloyd@gmail.com>
Expand Down Expand Up @@ -42,7 +43,7 @@ public function __construct(Client $client)
*
* @return Client
*/
protected function getClient()
protected function getClient(): Client
{
return $this->client;
}
Expand All @@ -52,13 +53,17 @@ protected function getClient()
*
* @return string
*/
protected function getApiVersion()
protected function getApiVersion(): string
{
return $this->client->getApiVersion();
}

/**
* @return $this
*/
public function configure()
{
return $this;
}

/**
Expand All @@ -70,7 +75,7 @@ public function configure()
*
* @return array|string
*/
protected function get($path, array $parameters = [], array $requestHeaders = [])
protected function get(string $path, array $parameters = [], array $requestHeaders = [])
{
if (null !== $this->perPage && !isset($parameters['per_page'])) {
$parameters['per_page'] = $this->perPage;
Expand All @@ -96,9 +101,9 @@ protected function get($path, array $parameters = [], array $requestHeaders = []
* @param array $parameters HEAD parameters.
* @param array $requestHeaders Request headers.
*
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
protected function head($path, array $parameters = [], array $requestHeaders = [])
protected function head(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
{
if (array_key_exists('ref', $parameters) && null === $parameters['ref']) {
unset($parameters['ref']);
Expand All @@ -116,7 +121,7 @@ protected function head($path, array $parameters = [], array $requestHeaders = [
*
* @return array|string
*/
protected function post($path, array $parameters = [], array $requestHeaders = [])
protected function post(string $path, array $parameters = [], array $requestHeaders = [])
{
return $this->postRaw(
$path,
Expand All @@ -134,7 +139,7 @@ protected function post($path, array $parameters = [], array $requestHeaders = [
*
* @return array|string
*/
protected function postRaw($path, $body, array $requestHeaders = [])
protected function postRaw(string $path, $body, array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->post(
$path,
Expand All @@ -154,7 +159,7 @@ protected function postRaw($path, $body, array $requestHeaders = [])
*
* @return array|string
*/
protected function patch($path, array $parameters = [], array $requestHeaders = [])
protected function patch(string $path, array $parameters = [], array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->patch(
$path,
Expand All @@ -174,7 +179,7 @@ protected function patch($path, array $parameters = [], array $requestHeaders =
*
* @return array|string
*/
protected function put($path, array $parameters = [], array $requestHeaders = [])
protected function put(string $path, array $parameters = [], array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->put(
$path,
Expand All @@ -194,7 +199,7 @@ protected function put($path, array $parameters = [], array $requestHeaders = []
*
* @return array|string
*/
protected function delete($path, array $parameters = [], array $requestHeaders = [])
protected function delete(string $path, array $parameters = [], array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->delete(
$path,
Expand All @@ -212,7 +217,7 @@ protected function delete($path, array $parameters = [], array $requestHeaders =
*
* @return string|null
*/
protected function createJsonBody(array $parameters)
protected function createJsonBody(array $parameters): ?string
{
return (count($parameters) === 0) ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0);
}
Expand Down
18 changes: 10 additions & 8 deletions lib/Github/Api/AcceptHeaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Github\Api;

use Psr\Http\Message\ResponseInterface;

/**
* A trait to make sure we add accept headers on all requests.
*
Expand All @@ -12,37 +14,37 @@ trait AcceptHeaderTrait
/** @var string */
protected $acceptHeaderValue;

protected function get($path, array $parameters = [], array $requestHeaders = [])
protected function get(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::get($path, $parameters, $this->mergeHeaders($requestHeaders));
}

protected function head($path, array $parameters = [], array $requestHeaders = [])
protected function head(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
{
return parent::head($path, $parameters, $this->mergeHeaders($requestHeaders));
}

protected function post($path, array $parameters = [], array $requestHeaders = [])
protected function post(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::post($path, $parameters, $this->mergeHeaders($requestHeaders));
}

protected function postRaw($path, $body, array $requestHeaders = [])
protected function postRaw(string $path, $body, array $requestHeaders = [])
{
return parent::postRaw($path, $body, $this->mergeHeaders($requestHeaders));
}

protected function patch($path, array $parameters = [], array $requestHeaders = [])
protected function patch(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::patch($path, $parameters, $this->mergeHeaders($requestHeaders));
}

protected function put($path, array $parameters = [], array $requestHeaders = [])
protected function put(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::put($path, $parameters, $this->mergeHeaders($requestHeaders));
}

protected function delete($path, array $parameters = [], array $requestHeaders = [])
protected function delete(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::delete($path, $parameters, $this->mergeHeaders($requestHeaders));
}
Expand All @@ -52,7 +54,7 @@ protected function delete($path, array $parameters = [], array $requestHeaders =
*
* @return array
*/
private function mergeHeaders(array $headers = [])
private function mergeHeaders(array $headers = []): array
{
$default = [];
if ($this->acceptHeaderValue) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/CurrentUser/Starring.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Starring extends AbstractApi
*
* @param string $bodyType
*
* @return self
* @return $this
*/
public function configure($bodyType = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/Gist/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Comments extends AbstractApi
*
* @param string|null $bodyType
*
* @return self
* @return $this
*/
public function configure($bodyType = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/Gists.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Gists extends AbstractApi
*
* @param string|null $bodyType
*
* @return self
* @return $this
*/
public function configure($bodyType = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/GitData/Blobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Blobs extends AbstractApi
*
* @param string|null $bodyType
*
* @return self
* @return $this
*/
public function configure($bodyType = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Issue extends AbstractApi
*
* @param string|null $bodyType
*
* @return self
* @return $this
*/
public function configure($bodyType = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/Issue/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Comments extends AbstractApi
*
* @param string|null $bodyType
*
* @return self
* @return $this
*/
public function configure($bodyType = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/Project/AbstractProjectApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class AbstractProjectApi extends AbstractApi
*
* @see https://developer.github.com/v3/repos/projects/#projects
*
* @return self
* @return $this
*/
public function configure()
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/Project/Cards.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Cards extends AbstractApi
*
* @see https://developer.github.com/v3/repos/projects/#projects
*
* @return self
* @return $this
*/
public function configure()
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/PullRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PullRequest extends AbstractApi
* @param string|null $bodyType
* @param string|null $apiVersion
*
* @return self
* @return $this
*/
public function configure($bodyType = null, $apiVersion = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/PullRequest/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Comments extends AbstractApi
* @param string|null $bodyType
* @param string|null $apiVersion
*
* @return self
* @return $this
*/
public function configure($bodyType = null, $apiVersion = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/Repository/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Comments extends AbstractApi
*
* @param string|null $bodyType
*
* @return self
* @return $this
*/
public function configure($bodyType = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/Repository/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Contents extends AbstractApi
*
* @param string|null $bodyType
*
* @return self
* @return $this
*/
public function configure($bodyType = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/Repository/Stargazers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Stargazers extends AbstractApi
*
* @param string $bodyType
*
* @return self
* @return $this
*/
public function configure($bodyType = null)
{
Expand Down
23 changes: 12 additions & 11 deletions lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Http\Discovery\Psr17FactoryDiscovery;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\ResponseInterface;

/**
* Simple yet very cool PHP GitHub client.
Expand Down Expand Up @@ -142,7 +143,7 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul
*
* @return Client
*/
public static function createWithHttpClient(ClientInterface $httpClient)
public static function createWithHttpClient(ClientInterface $httpClient): self
{
$builder = new Builder($httpClient);

Expand All @@ -156,7 +157,7 @@ public static function createWithHttpClient(ClientInterface $httpClient)
*
* @return AbstractApi
*/
public function api($name)
public function api($name): AbstractApi
{
switch ($name) {
case 'me':
Expand Down Expand Up @@ -311,7 +312,7 @@ public function api($name)
*
* @return void
*/
public function authenticate($tokenOrLogin, $password = null, $authMethod = null)
public function authenticate($tokenOrLogin, $password = null, $authMethod = null): void
{
if (null === $authMethod && (self::AUTH_JWT === $password || self::AUTH_ACCESS_TOKEN === $password)) {
$authMethod = $password;
Expand All @@ -333,7 +334,7 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null
*
* @return void
*/
private function setEnterpriseUrl($enterpriseUrl)
private function setEnterpriseUrl($enterpriseUrl): void
{
$builder = $this->getHttpClientBuilder();
$builder->removePlugin(Plugin\AddHostPlugin::class);
Expand All @@ -346,7 +347,7 @@ private function setEnterpriseUrl($enterpriseUrl)
/**
* @return string
*/
public function getApiVersion()
public function getApiVersion(): string
{
return $this->apiVersion;
}
Expand All @@ -359,7 +360,7 @@ public function getApiVersion()
*
* @return void
*/
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
public function addCache(CacheItemPoolInterface $cachePool, array $config = []): void
{
$this->getHttpClientBuilder()->addCache($cachePool, $config);
}
Expand All @@ -369,7 +370,7 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
*
* @return void
*/
public function removeCache()
public function removeCache(): void
{
$this->getHttpClientBuilder()->removeCache();
}
Expand All @@ -380,7 +381,7 @@ public function removeCache()
*
* @return AbstractApi
*/
public function __call($name, $args)
public function __call($name, $args): AbstractApi
{
try {
return $this->api($name);
Expand All @@ -392,23 +393,23 @@ public function __call($name, $args)
/**
* @return null|\Psr\Http\Message\ResponseInterface
*/
public function getLastResponse()
public function getLastResponse(): ?ResponseInterface
{
return $this->responseHistory->getLastResponse();
}

/**
* @return HttpMethodsClientInterface
*/
public function getHttpClient()
public function getHttpClient(): HttpMethodsClientInterface
{
return $this->getHttpClientBuilder()->getHttpClient();
}

/**
* @return Builder
*/
protected function getHttpClientBuilder()
protected function getHttpClientBuilder(): Builder
{
return $this->httpClientBuilder;
}
Expand Down
Loading