Skip to content

Commit

Permalink
Merge pull request #468 from markwalet/php-84-deprecations
Browse files Browse the repository at this point in the history
Fix | Resolve PHP 8.4 deprecation warnings
  • Loading branch information
Sammyjo20 authored Dec 3, 2024
2 parents ca726dc + 86f5206 commit d5bb5d6
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidResponseClassException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class InvalidResponseClassException extends SaloonException
/**
* Constructor
*/
public function __construct(string $message = null)
public function __construct(?string $message = null)
{
parent::__construct($message ?? sprintf('The provided response must exist and implement the %s contract.', Response::class));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidStateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class InvalidStateException extends SaloonException
{
public function __construct(string $message = null, int $code = 0, ?Throwable $previous = null)
public function __construct(?string $message = null, int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message ?? 'Invalid state.', $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/RequestExceptionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RequestExceptionHelper
/**
* Create the request exception from a response
*/
public static function create(Response $response, Throwable $previous = null): RequestException
public static function create(Response $response, ?Throwable $previous = null): RequestException
{
$status = $response->status();

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Faking/Fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Fixture
/**
* Constructor
*/
public function __construct(string $name = '', Storage $storage = null)
public function __construct(string $name = '', ?Storage $storage = null)
{
$this->name = $name;
$this->storage = $storage ?? new Storage(MockConfig::getFixturePath(), true);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Faking/MockClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function assertNothingSent(): void
/**
* Assert a request count has been met.
*/
public function assertSentCount(int $count, string $requestClass = null): void
public function assertSentCount(int $count, ?string $requestClass = null): void
{
if (is_string($requestClass)) {
$actualCount = $this->getRequestSentCount()[$requestClass] ?? 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class PendingRequest
/**
* Build up the request payload.
*/
public function __construct(Connector $connector, Request $request, MockClient $mockClient = null)
public function __construct(Connector $connector, Request $request, ?MockClient $mockClient = null)
{
// Let's start by getting our PSR factory collection. This object contains all the
// relevant factories for creating PSR-7 requests as well as URIs and streams.
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Response
/**
* Create a new response instance.
*/
public function __construct(ResponseInterface $psrResponse, PendingRequest $pendingRequest, RequestInterface $psrRequest, Throwable $senderException = null)
public function __construct(ResponseInterface $psrResponse, PendingRequest $pendingRequest, RequestInterface $psrRequest, ?Throwable $senderException = null)
{
$this->psrRequest = $psrRequest;
$this->psrResponse = $psrResponse;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Senders/GuzzleSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function (TransferException $guzzleException) use ($pendingRequest, $psrRequest)
/**
* Create a response.
*/
protected function createResponse(ResponseInterface $psrResponse, PendingRequest $pendingRequest, RequestInterface $psrRequest, Exception $exception = null): Response
protected function createResponse(ResponseInterface $psrResponse, PendingRequest $pendingRequest, RequestInterface $psrRequest, ?Exception $exception = null): Response
{
/** @var class-string<\Saloon\Http\Response> $responseClass */
$responseClass = $pendingRequest->getResponseClass();
Expand Down
4 changes: 2 additions & 2 deletions src/Repositories/Body/MultipartBodyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MultipartBodyRepository implements BodyRepository, MergeableBody
* @param array<\Saloon\Data\MultipartValue> $value
* @throws \Exception
*/
public function __construct(array $value = [], string $boundary = null)
public function __construct(array $value = [], ?string $boundary = null)
{
$this->data = new ArrayBodyRepository;
$this->boundary = is_null($boundary) ? StringHelpers::random(40) : $boundary;
Expand Down Expand Up @@ -90,7 +90,7 @@ public function merge(array ...$arrays): static
* @param array<string, mixed> $headers
* @return $this
*/
public function add(string $name, mixed $contents, string $filename = null, array $headers = []): static
public function add(string $name, mixed $contents, ?string $filename = null, array $headers = []): static
{
$this->attach(new MultipartValue($name, $contents, $filename, $headers));

Expand Down
8 changes: 4 additions & 4 deletions src/Traits/Connector/SendsRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait SendsRequests
*
* @param callable(\Throwable, \Saloon\Http\Request): (bool)|null $handleRetry
*/
public function send(Request $request, MockClient $mockClient = null, callable $handleRetry = null): Response
public function send(Request $request, ?MockClient $mockClient = null, ?callable $handleRetry = null): Response
{
if (is_null($handleRetry)) {
$handleRetry = static fn (): bool => true;
Expand Down Expand Up @@ -126,7 +126,7 @@ public function send(Request $request, MockClient $mockClient = null, callable $
/**
* Send a request asynchronously
*/
public function sendAsync(Request $request, MockClient $mockClient = null): PromiseInterface
public function sendAsync(Request $request, ?MockClient $mockClient = null): PromiseInterface
{
$sender = $this->sender();

Expand Down Expand Up @@ -163,7 +163,7 @@ public function sendAsync(Request $request, MockClient $mockClient = null): Prom
*
* @param callable(\Throwable, \Saloon\Http\Request): (bool)|null $handleRetry
*/
public function sendAndRetry(Request $request, int $tries, int $interval = 0, callable $handleRetry = null, bool $throw = true, MockClient $mockClient = null, bool $useExponentialBackoff = false): Response
public function sendAndRetry(Request $request, int $tries, int $interval = 0, ?callable $handleRetry = null, bool $throw = true, ?MockClient $mockClient = null, bool $useExponentialBackoff = false): Response
{
$request->tries = $tries;
$request->retryInterval = $interval;
Expand All @@ -176,7 +176,7 @@ public function sendAndRetry(Request $request, int $tries, int $interval = 0, ca
/**
* Create a new PendingRequest
*/
public function createPendingRequest(Request $request, MockClient $mockClient = null): PendingRequest
public function createPendingRequest(Request $request, ?MockClient $mockClient = null): PendingRequest
{
return new PendingRequest($this, $request, $mockClient);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/OAuth2/AuthorizationCodeGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ trait AuthorizationCodeGrant
*
* @param array<string> $scopes
*/
public function getAuthorizationUrl(array $scopes = [], string $state = null, string $scopeSeparator = ' ', array $additionalQueryParameters = []): string
public function getAuthorizationUrl(array $scopes = [], ?string $state = null, string $scopeSeparator = ' ', array $additionalQueryParameters = []): string
{
$config = $this->oauthConfig();

Expand Down Expand Up @@ -72,7 +72,7 @@ public function getAuthorizationUrl(array $scopes = [], string $state = null, st
* @param callable(TRequest): (void)|null $requestModifier
* @throws \Saloon\Exceptions\InvalidStateException
*/
public function getAccessToken(string $code, string $state = null, string $expectedState = null, bool $returnResponse = false, ?callable $requestModifier = null): OAuthAuthenticator|Response
public function getAccessToken(string $code, ?string $state = null, ?string $expectedState = null, bool $returnResponse = false, ?callable $requestModifier = null): OAuthAuthenticator|Response
{
$this->oauthConfig()->validate();

Expand Down Expand Up @@ -140,7 +140,7 @@ public function refreshAccessToken(OAuthAuthenticator|string $refreshToken, bool
/**
* Create the OAuthAuthenticator from a response.
*/
protected function createOAuthAuthenticatorFromResponse(Response $response, string $fallbackRefreshToken = null): OAuthAuthenticator
protected function createOAuthAuthenticatorFromResponse(Response $response, ?string $fallbackRefreshToken = null): OAuthAuthenticator
{
$responseData = $response->object();

Expand Down
6 changes: 3 additions & 3 deletions src/Traits/Request/HasConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ public function sender(): Sender
/**
* Create a pending request
*/
public function createPendingRequest(MockClient $mockClient = null): PendingRequest
public function createPendingRequest(?MockClient $mockClient = null): PendingRequest
{
return $this->connector()->createPendingRequest($this, $mockClient);
}

/**
* Send a request synchronously
*/
public function send(MockClient $mockClient = null): Response
public function send(?MockClient $mockClient = null): Response
{
return $this->connector()->send($this, $mockClient);
}

/**
* Send a request asynchronously
*/
public function sendAsync(MockClient $mockClient = null): PromiseInterface
public function sendAsync(?MockClient $mockClient = null): PromiseInterface
{
return $this->connector()->sendAsync($this, $mockClient);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Connectors/RetryConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class RetryConnector extends TestConnector
{
public function __construct(int $tries = null, int $retryInterval = 0, bool $throwOnMaxTries = null, protected ?Closure $handleRetry = null)
public function __construct(?int $tries = null, int $retryInterval = 0, ?bool $throwOnMaxTries = null, protected ?Closure $handleRetry = null)
{
// These are just for us to test the various retries

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Requests/RetryUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function resolveEndpoint(): string
return '/user';
}

public function __construct(int $tries = null, int $retryInterval = 0, bool $throwOnMaxTries = null, protected ?Closure $handleRetry = null)
public function __construct(?int $tries = null, int $retryInterval = 0, ?bool $throwOnMaxTries = null, protected ?Closure $handleRetry = null)
{
// These are just for us to test the various retries

Expand Down

0 comments on commit d5bb5d6

Please sign in to comment.