diff --git a/lib/Github/Api/AcceptHeaderTrait.php b/lib/Github/Api/AcceptHeaderTrait.php index e788fd1ca5e..3d22824fdba 100644 --- a/lib/Github/Api/AcceptHeaderTrait.php +++ b/lib/Github/Api/AcceptHeaderTrait.php @@ -9,6 +9,7 @@ */ trait AcceptHeaderTrait { + /** @var string */ protected $acceptHeaderValue; protected function get($path, array $parameters = [], array $requestHeaders = []) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 2052461335d..9b27c346677 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -333,6 +333,8 @@ public function api($name) * @param null|string $authMethod One of the AUTH_* class constants * * @throws InvalidArgumentException If no authentication method was given + * + * @return void */ public function authenticate($tokenOrLogin, $password = null, $authMethod = null) { @@ -357,6 +359,8 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null * Sets the URL of your GitHub Enterprise instance. * * @param string $enterpriseUrl URL of the API in the form of http(s)://hostname + * + * @return void */ private function setEnterpriseUrl($enterpriseUrl) { @@ -381,6 +385,8 @@ public function getApiVersion() * * @param CacheItemPoolInterface $cachePool * @param array $config + * + * @return void */ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) { @@ -389,6 +395,8 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) /** * Remove the cache plugin. + * + * @return void */ public function removeCache() { @@ -397,8 +405,7 @@ public function removeCache() /** * @param string $name - * - * @throws BadMethodCallException + * @param array $args * * @return ApiInterface */ diff --git a/lib/Github/Exception/ApiLimitExceedException.php b/lib/Github/Exception/ApiLimitExceedException.php index 0283175f19b..f2dd9b874d6 100644 --- a/lib/Github/Exception/ApiLimitExceedException.php +++ b/lib/Github/Exception/ApiLimitExceedException.php @@ -9,9 +9,17 @@ */ class ApiLimitExceedException extends RuntimeException { + /** @var int */ private $limit; + /** @var int */ private $reset; + /** + * @param int $limit + * @param int $reset + * @param int $code + * @param \Throwable|null $previous + */ public function __construct($limit = 5000, $reset = 1800, $code = 0, $previous = null) { $this->limit = (int) $limit; @@ -20,11 +28,17 @@ public function __construct($limit = 5000, $reset = 1800, $code = 0, $previous = parent::__construct(sprintf('You have reached GitHub hourly limit! Actual limit is: %d', $limit), $code, $previous); } + /** + * @return int + */ public function getLimit() { return $this->limit; } + /** + * @return int + */ public function getResetTime() { return $this->reset; diff --git a/lib/Github/Exception/MissingArgumentException.php b/lib/Github/Exception/MissingArgumentException.php index f5e46ef68aa..7a14bb51ae7 100644 --- a/lib/Github/Exception/MissingArgumentException.php +++ b/lib/Github/Exception/MissingArgumentException.php @@ -9,6 +9,11 @@ */ class MissingArgumentException extends ErrorException { + /** + * @param string|array $required + * @param int $code + * @param \Throwable|null $previous + */ public function __construct($required, $code = 0, $previous = null) { if (is_string($required)) { diff --git a/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php b/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php index 6f93fe40b14..0e63b277ce6 100644 --- a/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php +++ b/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php @@ -4,14 +4,23 @@ class TwoFactorAuthenticationRequiredException extends RuntimeException { + /** @var string */ private $type; + /** + * @param string $type + * @param int $code + * @param \Throwable|null $previous + */ public function __construct($type, $code = 0, $previous = null) { $this->type = $type; parent::__construct('Two factor authentication is enabled on this account', $code, $previous); } + /** + * @return string + */ public function getType() { return $this->type; diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 3b05b8fecc5..90263cb6632 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -113,6 +113,8 @@ public function getHttpClient() * Add a new plugin to the end of the plugin chain. * * @param Plugin $plugin + * + * @return void */ public function addPlugin(Plugin $plugin) { @@ -124,6 +126,8 @@ public function addPlugin(Plugin $plugin) * Remove a plugin by its fully qualified class name (FQCN). * * @param string $fqcn + * + * @return void */ public function removePlugin($fqcn) { @@ -137,6 +141,8 @@ public function removePlugin($fqcn) /** * Clears used headers. + * + * @return void */ public function clearHeaders() { @@ -148,6 +154,8 @@ public function clearHeaders() /** * @param array $headers + * + * @return void */ public function addHeaders(array $headers) { @@ -160,6 +168,8 @@ public function addHeaders(array $headers) /** * @param string $header * @param string $headerValue + * + * @return void */ public function addHeaderValue($header, $headerValue) { @@ -178,6 +188,8 @@ public function addHeaderValue($header, $headerValue) * * @param CacheItemPoolInterface $cachePool * @param array $config + * + * @return void */ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) { @@ -190,6 +202,8 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) /** * Remove the cache plugin. + * + * @return void */ public function removeCache() { diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index dcab5b4a979..67cc7016c54 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -56,13 +56,19 @@ public static function getPagination(ResponseInterface $response) */ public static function getApiLimit(ResponseInterface $response) { - $remainingCalls = self::getHeader($response, 'X-RateLimit-Remaining'); + $remainingCallsHeader = self::getHeader($response, 'X-RateLimit-Remaining'); - if (null !== $remainingCalls && 1 > $remainingCalls) { + if (null === $remainingCallsHeader) { + return null; + } + + $remainingCalls = (int) $remainingCallsHeader; + + if (1 > $remainingCalls) { throw new ApiLimitExceedException($remainingCalls); } - return $remainingCalls; + return $remainingCallsHeader; } /** diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index de6237bef8b..a70593b8791 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -5,6 +5,7 @@ use Github\Client; use Github\Exception\RuntimeException; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -16,10 +17,18 @@ class Authentication implements Plugin { use Plugin\VersionBridgePlugin; + /** @var string */ private $tokenOrLogin; + /** @var string|null */ private $password; + /** @var string|null */ private $method; + /** + * @param string $tokenOrLogin + * @param string|null $password + * @param string|null $method + */ public function __construct($tokenOrLogin, $password, $method) { $this->tokenOrLogin = $tokenOrLogin; @@ -28,7 +37,7 @@ public function __construct($tokenOrLogin, $password, $method) } /** - * {@inheritdoc} + * @return Promise */ public function doHandleRequest(RequestInterface $request, callable $next, callable $first) { diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index dde0b45ccff..60382074a40 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -9,6 +9,7 @@ use Github\Exception\ValidationFailedException; use Github\HttpClient\Message\ResponseMediator; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -21,7 +22,7 @@ class GithubExceptionThrower implements Plugin use Plugin\VersionBridgePlugin; /** - * {@inheritdoc} + * @return Promise */ public function doHandleRequest(RequestInterface $request, callable $next, callable $first) { @@ -33,8 +34,8 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla // If error: $remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining'); if (null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) { - $limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); - $reset = ResponseMediator::getHeader($response, 'X-RateLimit-Reset'); + $limit = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); + $reset = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Reset'); throw new ApiLimitExceedException($limit, $reset); } diff --git a/lib/Github/HttpClient/Plugin/History.php b/lib/Github/HttpClient/Plugin/History.php index 0f59bbb65f9..c23621b87ed 100644 --- a/lib/Github/HttpClient/Plugin/History.php +++ b/lib/Github/HttpClient/Plugin/History.php @@ -28,6 +28,9 @@ public function getLastResponse() return $this->lastResponse; } + /** + * @return void + */ public function addSuccess(RequestInterface $request, ResponseInterface $response) { $this->lastResponse = $response; diff --git a/lib/Github/HttpClient/Plugin/HistoryTrait.php b/lib/Github/HttpClient/Plugin/HistoryTrait.php index fbc5335d318..611db512917 100644 --- a/lib/Github/HttpClient/Plugin/HistoryTrait.php +++ b/lib/Github/HttpClient/Plugin/HistoryTrait.php @@ -15,6 +15,9 @@ */ trait HistoryTrait { + /** + * @return void + */ public function addFailure(RequestInterface $request, ClientExceptionInterface $exception) { } @@ -25,6 +28,9 @@ public function addFailure(RequestInterface $request, ClientExceptionInterface $ */ trait HistoryTrait { + /** + * @return void + */ public function addFailure(RequestInterface $request, Exception $exception) { } diff --git a/lib/Github/HttpClient/Plugin/PathPrepend.php b/lib/Github/HttpClient/Plugin/PathPrepend.php index 1245c6923a2..3c55f72f13c 100644 --- a/lib/Github/HttpClient/Plugin/PathPrepend.php +++ b/lib/Github/HttpClient/Plugin/PathPrepend.php @@ -3,6 +3,7 @@ namespace Github\HttpClient\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -14,6 +15,7 @@ class PathPrepend implements Plugin { use Plugin\VersionBridgePlugin; + /** @var string */ private $path; /** @@ -25,7 +27,11 @@ public function __construct($path) } /** - * {@inheritdoc} + * @param RequestInterface $request + * @param callable $next + * @param callable $first + * + * @return Promise */ public function doHandleRequest(RequestInterface $request, callable $next, callable $first) { diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 24f2a32f135..defcde23e6a 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -161,6 +161,8 @@ public function fetchLast() /** * @param string $key + * + * @return bool */ protected function has($key) { @@ -169,6 +171,8 @@ protected function has($key) /** * @param string $key + * + * @return array */ protected function get($key) { @@ -178,6 +182,8 @@ protected function get($key) return ResponseMediator::getContent($result); } + + return []; } /** diff --git a/lib/Github/ResultPagerInterface.php b/lib/Github/ResultPagerInterface.php index c5add903648..80660247900 100644 --- a/lib/Github/ResultPagerInterface.php +++ b/lib/Github/ResultPagerInterface.php @@ -43,6 +43,8 @@ public function fetchAll(ApiInterface $api, $method, array $parameters = []); /** * Method that performs the actual work to refresh the pagination property. + * + * @return void */ public function postFetch(); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 1c57e1fef7e..9e84171f2c5 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,4 +1,15 @@ parameters: - level: 4 + checkMissingIterableValueType: false + + level: 6 paths: - lib + + ignoreErrors: + # Ignore typehint errors on api classes + - + message: '#Method (.*) with no typehint specified\.#' + path: lib/Github/Api + - + message: '#Method (.*) has no return typehint specified\.#' + path: lib/Github/Api