Skip to content

Commit

Permalink
Merge branch 'v3' into add-fixture-context
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammyjo20 authored Dec 3, 2024
2 parents afec902 + d5bb5d6 commit 8415490
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.3'
coverage: none

- name: Install composer dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fail-fast: true
matrix:
os: [ ubuntu-latest, windows-latest ]
php: [ 8.1, 8.2, 8.3 ]
php: [ 8.1, 8.2, 8.3, 8.4 ]
stability: [ prefer-lowest, prefer-stable ]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
Expand Down
5 changes: 0 additions & 5 deletions phpstan.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ parameters:
count: 1
path: src/Http/Faking/MockClient.php

-
message: "#^Result of \\&\\& is always false.$#"
count: 1
path: src/Data/MultipartValue.php

-
message: "#^Parameter \\#1 \\$response of method Saloon\\\\Http\\\\PendingRequest\\:\\:executeResponsePipeline\\(\\) expects Saloon\\\\Http\\\\Response\\, GuzzleHttp\\\\Promise\\\\PromiseInterface\\|Saloon\\\\Http\\\\Response given.$#"
count: 1
Expand Down
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 @@ -38,7 +38,7 @@ class Fixture
/**
* Constructor
*/
public function __construct(string $name = '', Storage $storage = null, ArrayStoreContract $context = null)
public function __construct(string $name = '', ?Storage $storage = null, ArrayStoreContract $context = null)
{
$this->name = $name;
$this->storage = $storage ?? new Storage(MockConfig::getFixturePath(), true);
Expand Down
8 changes: 4 additions & 4 deletions 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 Expand Up @@ -352,7 +352,7 @@ public function findResponseByRequest(string $request, ?int $index = null): ?Res
return null;
}

if(! is_null($index)) {
if (! is_null($index)) {
$recordedResponse = $this->getRecordedResponses()[$index];

if ($recordedResponse->getPendingRequest()->getRequest() instanceof $request) {
Expand Down Expand Up @@ -384,7 +384,7 @@ public function findResponseByRequestUrl(string $url, ?int $index = null): ?Resp
return null;
}

if(! is_null($index)) {
if (! is_null($index)) {
$response = $this->getRecordedResponses()[$index];
$pendingRequest = $response->getPendingRequest();

Expand Down Expand Up @@ -451,7 +451,7 @@ private function checkClosureAgainstResponses(callable $closure, ?int $index = n
return false;
}

if(! is_null($index)) {
if (! is_null($index)) {
$response = $this->getRecordedResponses()[$index];
$request = $response->getPendingRequest()->getRequest();

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
10 changes: 5 additions & 5 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 @@ -93,7 +93,7 @@ public function send(Request $request, MockClient $mockClient = null, callable $
$exceptionResponse = $exception instanceof RequestException ? $exception->getResponse() : null;

// If the exception is a FatalRequestException, we'll execute the fatal pipeline
if($exception instanceof FatalRequestException) {
if ($exception instanceof FatalRequestException) {
$exception->getPendingRequest()->executeFatalPipeline($exception);
}

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 8415490

Please sign in to comment.