Skip to content

Commit d2d0fa6

Browse files
committed
phpstan level 6 fixes
1 parent 6a80368 commit d2d0fa6

15 files changed

+101
-9
lines changed

lib/Github/Api/AcceptHeaderTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
trait AcceptHeaderTrait
1111
{
12+
/** @var string */
1213
protected $acceptHeaderValue;
1314

1415
protected function get($path, array $parameters = [], array $requestHeaders = [])

lib/Github/Client.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ public function api($name)
333333
* @param null|string $authMethod One of the AUTH_* class constants
334334
*
335335
* @throws InvalidArgumentException If no authentication method was given
336+
*
337+
* @return void
336338
*/
337339
public function authenticate($tokenOrLogin, $password = null, $authMethod = null)
338340
{
@@ -357,6 +359,8 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null
357359
* Sets the URL of your GitHub Enterprise instance.
358360
*
359361
* @param string $enterpriseUrl URL of the API in the form of http(s)://hostname
362+
*
363+
* @return void
360364
*/
361365
private function setEnterpriseUrl($enterpriseUrl)
362366
{
@@ -381,6 +385,8 @@ public function getApiVersion()
381385
*
382386
* @param CacheItemPoolInterface $cachePool
383387
* @param array $config
388+
*
389+
* @return void
384390
*/
385391
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
386392
{
@@ -389,6 +395,8 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
389395

390396
/**
391397
* Remove the cache plugin.
398+
*
399+
* @return void
392400
*/
393401
public function removeCache()
394402
{
@@ -397,8 +405,7 @@ public function removeCache()
397405

398406
/**
399407
* @param string $name
400-
*
401-
* @throws BadMethodCallException
408+
* @param array $args
402409
*
403410
* @return ApiInterface
404411
*/

lib/Github/Exception/ApiLimitExceedException.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99
*/
1010
class ApiLimitExceedException extends RuntimeException
1111
{
12+
/** @var int */
1213
private $limit;
14+
/** @var int */
1315
private $reset;
1416

17+
/**
18+
* @param int $limit
19+
* @param int $reset
20+
* @param int $code
21+
* @param \Throwable|null $previous
22+
*/
1523
public function __construct($limit = 5000, $reset = 1800, $code = 0, $previous = null)
1624
{
1725
$this->limit = (int) $limit;
@@ -20,11 +28,17 @@ public function __construct($limit = 5000, $reset = 1800, $code = 0, $previous =
2028
parent::__construct(sprintf('You have reached GitHub hourly limit! Actual limit is: %d', $limit), $code, $previous);
2129
}
2230

31+
/**
32+
* @return int
33+
*/
2334
public function getLimit()
2435
{
2536
return $this->limit;
2637
}
2738

39+
/**
40+
* @return int
41+
*/
2842
public function getResetTime()
2943
{
3044
return $this->reset;

lib/Github/Exception/MissingArgumentException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
*/
1010
class MissingArgumentException extends ErrorException
1111
{
12+
/**
13+
* @param string|array $required
14+
* @param int $code
15+
* @param \Throwable|null $previous
16+
*/
1217
public function __construct($required, $code = 0, $previous = null)
1318
{
1419
if (is_string($required)) {

lib/Github/Exception/TwoFactorAuthenticationRequiredException.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@
44

55
class TwoFactorAuthenticationRequiredException extends RuntimeException
66
{
7+
/** @var string */
78
private $type;
89

10+
/**
11+
* @param string $type
12+
* @param int $code
13+
* @param \Throwable|null $previous
14+
*/
915
public function __construct($type, $code = 0, $previous = null)
1016
{
1117
$this->type = $type;
1218
parent::__construct('Two factor authentication is enabled on this account', $code, $previous);
1319
}
1420

21+
/**
22+
* @return string
23+
*/
1524
public function getType()
1625
{
1726
return $this->type;

lib/Github/HttpClient/Builder.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public function getHttpClient()
113113
* Add a new plugin to the end of the plugin chain.
114114
*
115115
* @param Plugin $plugin
116+
*
117+
* @return void
116118
*/
117119
public function addPlugin(Plugin $plugin)
118120
{
@@ -124,6 +126,8 @@ public function addPlugin(Plugin $plugin)
124126
* Remove a plugin by its fully qualified class name (FQCN).
125127
*
126128
* @param string $fqcn
129+
*
130+
* @return void
127131
*/
128132
public function removePlugin($fqcn)
129133
{
@@ -137,6 +141,8 @@ public function removePlugin($fqcn)
137141

138142
/**
139143
* Clears used headers.
144+
*
145+
* @return void
140146
*/
141147
public function clearHeaders()
142148
{
@@ -148,6 +154,8 @@ public function clearHeaders()
148154

149155
/**
150156
* @param array $headers
157+
*
158+
* @return void
151159
*/
152160
public function addHeaders(array $headers)
153161
{
@@ -160,6 +168,8 @@ public function addHeaders(array $headers)
160168
/**
161169
* @param string $header
162170
* @param string $headerValue
171+
*
172+
* @return void
163173
*/
164174
public function addHeaderValue($header, $headerValue)
165175
{
@@ -178,6 +188,8 @@ public function addHeaderValue($header, $headerValue)
178188
*
179189
* @param CacheItemPoolInterface $cachePool
180190
* @param array $config
191+
*
192+
* @return void
181193
*/
182194
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
183195
{
@@ -190,6 +202,8 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
190202

191203
/**
192204
* Remove the cache plugin.
205+
*
206+
* @return void
193207
*/
194208
public function removeCache()
195209
{

lib/Github/HttpClient/Message/ResponseMediator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static function getApiLimit(ResponseInterface $response)
5959
$remainingCalls = self::getHeader($response, 'X-RateLimit-Remaining');
6060

6161
if (null !== $remainingCalls && 1 > $remainingCalls) {
62-
throw new ApiLimitExceedException($remainingCalls);
62+
throw new ApiLimitExceedException((int) $remainingCalls);
6363
}
6464

6565
return $remainingCalls;

lib/Github/HttpClient/Plugin/Authentication.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Github\Client;
66
use Github\Exception\RuntimeException;
77
use Http\Client\Common\Plugin;
8+
use Http\Promise\Promise;
89
use Psr\Http\Message\RequestInterface;
910

1011
/**
@@ -16,10 +17,18 @@ class Authentication implements Plugin
1617
{
1718
use Plugin\VersionBridgePlugin;
1819

20+
/** @var string */
1921
private $tokenOrLogin;
22+
/** @var string|null */
2023
private $password;
24+
/** @var string|null */
2125
private $method;
2226

27+
/**
28+
* @param string $tokenOrLogin
29+
* @param string|null $password
30+
* @param string|null $method
31+
*/
2332
public function __construct($tokenOrLogin, $password, $method)
2433
{
2534
$this->tokenOrLogin = $tokenOrLogin;
@@ -28,7 +37,7 @@ public function __construct($tokenOrLogin, $password, $method)
2837
}
2938

3039
/**
31-
* {@inheritdoc}
40+
* @return Promise
3241
*/
3342
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
3443
{

lib/Github/HttpClient/Plugin/GithubExceptionThrower.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Github\Exception\ValidationFailedException;
1010
use Github\HttpClient\Message\ResponseMediator;
1111
use Http\Client\Common\Plugin;
12+
use Http\Promise\Promise;
1213
use Psr\Http\Message\RequestInterface;
1314
use Psr\Http\Message\ResponseInterface;
1415

@@ -21,7 +22,7 @@ class GithubExceptionThrower implements Plugin
2122
use Plugin\VersionBridgePlugin;
2223

2324
/**
24-
* {@inheritdoc}
25+
* @return Promise
2526
*/
2627
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
2728
{
@@ -33,8 +34,8 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla
3334
// If error:
3435
$remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining');
3536
if (null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) {
36-
$limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit');
37-
$reset = ResponseMediator::getHeader($response, 'X-RateLimit-Reset');
37+
$limit = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Limit');
38+
$reset = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Reset');
3839

3940
throw new ApiLimitExceedException($limit, $reset);
4041
}

lib/Github/HttpClient/Plugin/History.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public function getLastResponse()
2828
return $this->lastResponse;
2929
}
3030

31+
/**
32+
* @return void
33+
*/
3134
public function addSuccess(RequestInterface $request, ResponseInterface $response)
3235
{
3336
$this->lastResponse = $response;

lib/Github/HttpClient/Plugin/HistoryTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
trait HistoryTrait
1717
{
18+
/**
19+
* @return void
20+
*/
1821
public function addFailure(RequestInterface $request, ClientExceptionInterface $exception)
1922
{
2023
}
@@ -25,6 +28,9 @@ public function addFailure(RequestInterface $request, ClientExceptionInterface $
2528
*/
2629
trait HistoryTrait
2730
{
31+
/**
32+
* @return void
33+
*/
2834
public function addFailure(RequestInterface $request, Exception $exception)
2935
{
3036
}

lib/Github/HttpClient/Plugin/PathPrepend.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Github\HttpClient\Plugin;
44

55
use Http\Client\Common\Plugin;
6+
use Http\Promise\Promise;
67
use Psr\Http\Message\RequestInterface;
78

89
/**
@@ -14,6 +15,7 @@ class PathPrepend implements Plugin
1415
{
1516
use Plugin\VersionBridgePlugin;
1617

18+
/** @var string */
1719
private $path;
1820

1921
/**
@@ -25,7 +27,11 @@ public function __construct($path)
2527
}
2628

2729
/**
28-
* {@inheritdoc}
30+
* @param RequestInterface $request
31+
* @param callable $next
32+
* @param callable $first
33+
*
34+
* @return Promise
2935
*/
3036
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
3137
{

lib/Github/ResultPager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ public function fetchLast()
161161

162162
/**
163163
* @param string $key
164+
*
165+
* @return bool
164166
*/
165167
protected function has($key)
166168
{
@@ -169,6 +171,8 @@ protected function has($key)
169171

170172
/**
171173
* @param string $key
174+
*
175+
* @return array
172176
*/
173177
protected function get($key)
174178
{
@@ -178,6 +182,8 @@ protected function get($key)
178182

179183
return ResponseMediator::getContent($result);
180184
}
185+
186+
return [];
181187
}
182188

183189
/**

lib/Github/ResultPagerInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public function fetchAll(ApiInterface $api, $method, array $parameters = []);
4343

4444
/**
4545
* Method that performs the actual work to refresh the pagination property.
46+
*
47+
* @return void
4648
*/
4749
public function postFetch();
4850

phpstan.neon.dist

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
parameters:
2-
level: 4
2+
level: 6
33
paths:
44
- lib
5+
6+
ignoreErrors:
7+
# Ignore typehint errors on api classes
8+
-
9+
message: '#Method (.*) with no typehint specified\.#'
10+
path: lib/Github/Api
11+
-
12+
message: '#Method (.*) has no return typehint specified\.#'
13+
path: lib/Github/Api

0 commit comments

Comments
 (0)