Skip to content
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

Fix implicit nullable types to avoid PHP 8.4 warnings #1144

Merged
merged 6 commits into from
Sep 23, 2024
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
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']

steps:
- uses: actions/checkout@v4
Expand All @@ -27,6 +27,8 @@ jobs:

- name: Run phpunit
run: vendor/bin/phpunit --verbose
env:
SYMFONY_DEPRECATIONS_HELPER: 'max[self]=0'

phpstan:
name: PHPStan
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"require-dev": {
"symfony/cache": "^5.1.8",
"guzzlehttp/psr7": "^1.7",
"guzzlehttp/psr7": "^2.7",
"http-interop/http-factory-guzzle": "^1.0",
"guzzlehttp/guzzle": "^7.2",
"php-http/mock-client": "^1.4.1",
Expand Down
4 changes: 2 additions & 2 deletions lib/Github/Api/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Notification extends AbstractApi
*
* @return array array of notifications
*/
public function all($includingRead = false, $participating = false, DateTime $since = null, DateTime $before = null)
public function all($includingRead = false, $participating = false, ?DateTime $since = null, ?DateTime $before = null)
{
$parameters = [
'all' => $includingRead,
Expand All @@ -54,7 +54,7 @@ public function all($includingRead = false, $participating = false, DateTime $si
*
* @param DateTime|null $since
*/
public function markRead(DateTime $since = null)
public function markRead(?DateTime $since = null)
{
$parameters = [];

Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Api/Repository/Actions/Workflows.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function usage(string $username, string $repository, $workflow)
*
* @return array|string empty
*/
public function dispatches(string $username, string $repository, $workflow, string $ref, array $inputs = null)
public function dispatches(string $username, string $repository, $workflow, string $ref, ?array $inputs = null)
{
if (is_string($workflow)) {
$workflow = rawurlencode($workflow);
Expand Down
6 changes: 3 additions & 3 deletions lib/Github/Api/Repository/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function show($username, $repository, $path = null, $reference = null, $r
*
* @return array information about the new file
*/
public function create($username, $repository, $path, $content, $message, $branch = null, array $committer = null)
public function create($username, $repository, $path, $content, $message, $branch = null, ?array $committer = null)
{
$url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path);

Expand Down Expand Up @@ -174,7 +174,7 @@ public function exists($username, $repository, $path, $reference = null)
*
* @return array information about the updated file
*/
public function update($username, $repository, $path, $content, $message, $sha, $branch = null, array $committer = null)
public function update($username, $repository, $path, $content, $message, $sha, $branch = null, ?array $committer = null)
{
$url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path);

Expand Down Expand Up @@ -215,7 +215,7 @@ public function update($username, $repository, $path, $content, $message, $sha,
*
* @return array information about the updated file
*/
public function rm($username, $repository, $path, $message, $sha, $branch = null, array $committer = null)
public function rm($username, $repository, $path, $message, $sha, $branch = null, ?array $committer = null)
{
$url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path);

Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Client
* @param string|null $apiVersion
* @param string|null $enterpriseUrl
*/
public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null)
public function __construct(?Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null)
{
$this->responseHistory = new History();
$this->httpClientBuilder = $builder = $httpClientBuilder ?? new Builder();
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Exception/ApiLimitExceedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ApiLimitExceedException extends RuntimeException
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(int $limit = 5000, int $reset = 1800, int $code = 0, Throwable $previous = null)
public function __construct(int $limit = 5000, int $reset = 1800, int $code = 0, ?Throwable $previous = null)
{
$this->limit = (int) $limit;
$this->reset = (int) $reset;
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Exception/MissingArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MissingArgumentException extends ErrorException
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($required, int $code = 0, Throwable $previous = null)
public function __construct($required, int $code = 0, ?Throwable $previous = null)
{
if (is_string($required)) {
$required = [$required];
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/Exception/SsoRequiredException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SsoRequiredException extends RuntimeException
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(string $url, int $code = 0, Throwable $previous = null)
public function __construct(string $url, int $code = 0, ?Throwable $previous = null)
{
$this->url = $url;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TwoFactorAuthenticationRequiredException extends RuntimeException
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(string $type, int $code = 0, Throwable $previous = null)
public function __construct(string $type, int $code = 0, ?Throwable $previous = null)
{
$this->type = $type;
parent::__construct('Two factor authentication is enabled on this account', $code, $previous);
Expand Down
6 changes: 3 additions & 3 deletions lib/Github/HttpClient/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class Builder
* @param StreamFactoryInterface|null $streamFactory
*/
public function __construct(
ClientInterface $httpClient = null,
RequestFactoryInterface $requestFactory = null,
StreamFactoryInterface $streamFactory = null
?ClientInterface $httpClient = null,
?RequestFactoryInterface $requestFactory = null,
?StreamFactoryInterface $streamFactory = null
) {
$this->httpClient = $httpClient ?? Psr18ClientDiscovery::find();
$this->requestFactory = $requestFactory ?? Psr17FactoryDiscovery::findRequestFactory();
Expand Down
2 changes: 1 addition & 1 deletion lib/Github/ResultPager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ResultPager implements ResultPagerInterface
*
* @return void
*/
public function __construct(Client $client, int $perPage = null)
public function __construct(Client $client, ?int $perPage = null)
{
if (null !== $perPage && ($perPage < 1 || $perPage > 100)) {
throw new ValueError(sprintf('%s::__construct(): Argument #2 ($perPage) must be between 1 and 100, or null', self::class));
Expand Down
3 changes: 2 additions & 1 deletion test/Github/Tests/Api/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Github\Api\AbstractApi;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Utils;
use Http\Client\Common\HttpMethodsClientInterface;

class AbstractApiTest extends TestCase
Expand Down Expand Up @@ -232,7 +233,7 @@ private function getPSR7Response($expectedArray)
return new Response(
200,
['Content-Type' => 'application/json'],
\GuzzleHttp\Psr7\stream_for(json_encode($expectedArray))
Utils::streamFor(json_encode($expectedArray))
);
}
}
3 changes: 2 additions & 1 deletion test/Github/Tests/Functional/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Github\AuthMethod;
use Github\Client;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Utils;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

/**
Expand Down Expand Up @@ -61,7 +62,7 @@ private function getCurrentUserResponse($username)
'Content-Type' => 'application/json',
];

$body = \GuzzleHttp\Psr7\stream_for(json_encode([
$body = Utils::streamFor(json_encode([
'login' => $username,
]));

Expand Down
7 changes: 4 additions & 3 deletions test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Github\HttpClient\Message\ResponseMediator;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Utils;

/**
* @author Tobias Nyholm <[email protected]>
Expand All @@ -16,7 +17,7 @@ public function testGetContent()
$response = new Response(
200,
['Content-Type' => 'application/json'],
\GuzzleHttp\Psr7\stream_for(json_encode($body))
Utils::streamFor(json_encode($body))
);

$this->assertEquals($body, ResponseMediator::getContent($response));
Expand All @@ -31,7 +32,7 @@ public function testGetContentNotJson()
$response = new Response(
200,
[],
\GuzzleHttp\Psr7\stream_for($body)
Utils::streamFor($body)
);

$this->assertEquals($body, ResponseMediator::getContent($response));
Expand All @@ -46,7 +47,7 @@ public function testGetContentInvalidJson()
$response = new Response(
200,
['Content-Type' => 'application/json'],
\GuzzleHttp\Psr7\stream_for($body)
Utils::streamFor($body)
);

$this->assertEquals($body, ResponseMediator::getContent($response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GithubExceptionThrowerTest extends TestCase
/**
* @dataProvider responseProvider
*/
public function testHandleRequest(ResponseInterface $response, ExceptionInterface $exception = null): void
public function testHandleRequest(ResponseInterface $response, ?ExceptionInterface $exception = null): void
{
$request = new Request('GET', 'https://api.github.com/issues');

Expand Down
7 changes: 4 additions & 3 deletions test/Github/Tests/Mock/PaginatedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Github\Tests\Mock;

use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Utils;

/**
* @author Tobias Nyholm <[email protected]>
Expand All @@ -18,10 +19,10 @@ public function __construct($loopCount, array $content = [])
$this->loopCount = $loopCount;
$this->content = $content;

parent::__construct(200, ['Content-Type' => 'application/json'], \GuzzleHttp\Psr7\stream_for(json_encode($content)));
parent::__construct(200, ['Content-Type' => 'application/json'], Utils::streamFor(json_encode($content)));
}

public function getHeader($header)
public function getHeader($header): array
{
if ($header === 'Link') {
if ($this->loopCount > 1) {
Expand All @@ -38,7 +39,7 @@ public function getHeader($header)
return parent::getHeader($header);
}

public function hasHeader($header)
public function hasHeader($header): bool
{
if ($header === 'Link') {
return true;
Expand Down