Skip to content

phpstan level 6 fixes #897

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 5 commits into from
Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions lib/Github/Api/AcceptHeaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
trait AcceptHeaderTrait
{
/** @var string */
protected $acceptHeaderValue;

protected function get($path, array $parameters = [], array $requestHeaders = [])
Expand Down
11 changes: 9 additions & 2 deletions lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -381,6 +385,8 @@ public function getApiVersion()
*
* @param CacheItemPoolInterface $cachePool
* @param array $config
*
* @return void
*/
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
{
Expand All @@ -389,6 +395,8 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = [])

/**
* Remove the cache plugin.
*
* @return void
*/
public function removeCache()
{
Expand All @@ -397,8 +405,7 @@ public function removeCache()

/**
* @param string $name
*
* @throws BadMethodCallException
* @param array $args
*
* @return ApiInterface
*/
Expand Down
14 changes: 14 additions & 0 deletions lib/Github/Exception/ApiLimitExceedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions lib/Github/Exception/MissingArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions lib/Github/HttpClient/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -137,6 +141,8 @@ public function removePlugin($fqcn)

/**
* Clears used headers.
*
* @return void
*/
public function clearHeaders()
{
Expand All @@ -148,6 +154,8 @@ public function clearHeaders()

/**
* @param array $headers
*
* @return void
*/
public function addHeaders(array $headers)
{
Expand All @@ -160,6 +168,8 @@ public function addHeaders(array $headers)
/**
* @param string $header
* @param string $headerValue
*
* @return void
*/
public function addHeaderValue($header, $headerValue)
{
Expand All @@ -178,6 +188,8 @@ public function addHeaderValue($header, $headerValue)
*
* @param CacheItemPoolInterface $cachePool
* @param array $config
*
* @return void
*/
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
{
Expand All @@ -190,6 +202,8 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = [])

/**
* Remove the cache plugin.
*
* @return void
*/
public function removeCache()
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/HttpClient/Message/ResponseMediator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function getApiLimit(ResponseInterface $response)
$remainingCalls = self::getHeader($response, 'X-RateLimit-Remaining');

if (null !== $remainingCalls && 1 > $remainingCalls) {
throw new ApiLimitExceedException($remainingCalls);
throw new ApiLimitExceedException((int) $remainingCalls);
}

return $remainingCalls;
Expand Down
11 changes: 10 additions & 1 deletion lib/Github/HttpClient/Plugin/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
Expand All @@ -28,7 +37,7 @@ public function __construct($tokenOrLogin, $password, $method)
}

/**
* {@inheritdoc}
* @return Promise
*/
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
{
Expand Down
7 changes: 4 additions & 3 deletions lib/Github/HttpClient/Plugin/GithubExceptionThrower.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,7 +22,7 @@ class GithubExceptionThrower implements Plugin
use Plugin\VersionBridgePlugin;

/**
* {@inheritdoc}
* @return Promise
*/
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
{
Expand All @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Github/HttpClient/Plugin/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public function getLastResponse()
return $this->lastResponse;
}

/**
* @return void
*/
public function addSuccess(RequestInterface $request, ResponseInterface $response)
{
$this->lastResponse = $response;
Expand Down
6 changes: 6 additions & 0 deletions lib/Github/HttpClient/Plugin/HistoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
trait HistoryTrait
{
/**
* @return void
*/
public function addFailure(RequestInterface $request, ClientExceptionInterface $exception)
{
}
Expand All @@ -25,6 +28,9 @@ public function addFailure(RequestInterface $request, ClientExceptionInterface $
*/
trait HistoryTrait
{
/**
* @return void
*/
public function addFailure(RequestInterface $request, Exception $exception)
{
}
Expand Down
8 changes: 7 additions & 1 deletion lib/Github/HttpClient/Plugin/PathPrepend.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Github\HttpClient\Plugin;

use Http\Client\Common\Plugin;
use Http\Promise\Promise;
use Psr\Http\Message\RequestInterface;

/**
Expand All @@ -14,6 +15,7 @@ class PathPrepend implements Plugin
{
use Plugin\VersionBridgePlugin;

/** @var string */
private $path;

/**
Expand All @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions lib/Github/ResultPager.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public function fetchLast()

/**
* @param string $key
*
* @return bool
*/
protected function has($key)
{
Expand All @@ -169,6 +171,8 @@ protected function has($key)

/**
* @param string $key
*
* @return array
*/
protected function get($key)
{
Expand All @@ -178,6 +182,8 @@ protected function get($key)

return ResponseMediator::getContent($result);
}

return [];
}

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/Github/ResultPagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
11 changes: 10 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
parameters:
level: 4
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