Skip to content

Commit

Permalink
Fixes for PHP 8.4 deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Mar 31, 2024
1 parent 2779e86 commit 3fe11f6
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 81 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
->setRules([
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'@PSR12:risky' => true,
'@Symfony' => true,
'declare_strict_types' => false,
'global_namespace_import' => false,
Expand Down
6 changes: 3 additions & 3 deletions src/BodySummarizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class BodySummarizer implements BodySummarizerInterface
*/
private $truncateAt;

public function __construct(int $truncateAt = null)
public function __construct(?int $truncateAt = null)
{
$this->truncateAt = $truncateAt;
}
Expand All @@ -22,7 +22,7 @@ public function __construct(int $truncateAt = null)
public function summarize(MessageInterface $message): ?string
{
return $this->truncateAt === null
? \GuzzleHttp\Psr7\Message::bodySummary($message)
: \GuzzleHttp\Psr7\Message::bodySummary($message, $this->truncateAt);
? Psr7\Message::bodySummary($message)
: Psr7\Message::bodySummary($message, $this->truncateAt);
}
}
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Client implements ClientInterface, \Psr\Http\Client\ClientInterface
*
* @param array $config Client configuration settings.
*
* @see \GuzzleHttp\RequestOptions for a list of available request options.
* @see RequestOptions for a list of available request options.
*/
public function __construct(array $config = [])
{
Expand Down Expand Up @@ -202,7 +202,7 @@ public function request(string $method, $uri = '', array $options = []): Respons
*
* @deprecated Client::getConfig will be removed in guzzlehttp/guzzle:8.0.
*/
public function getConfig(string $option = null)
public function getConfig(?string $option = null)
{
return $option === null
? $this->config
Expand Down
2 changes: 1 addition & 1 deletion src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ public function requestAsync(string $method, $uri, array $options = []): Promise
*
* @deprecated ClientInterface::getConfig will be removed in guzzlehttp/guzzle:8.0.
*/
public function getConfig(string $option = null);
public function getConfig(?string $option = null);
}
2 changes: 1 addition & 1 deletion src/Cookie/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function toArray(): array
}, $this->getIterator()->getArrayCopy());
}

public function clear(string $domain = null, string $path = null, string $name = null): void
public function clear(?string $domain = null, ?string $path = null, ?string $name = null): void
{
if (!$domain) {
$this->cookies = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Cookie/CookieJarInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function setCookie(SetCookie $cookie): bool;
* @param string|null $path Clears cookies matching a domain and path
* @param string|null $name Clears cookies matching a domain, path, and name
*/
public function clear(string $domain = null, string $path = null, string $name = null): void;
public function clear(?string $domain = null, ?string $path = null, ?string $name = null): void;

/**
* Discard all sessions cookies.
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/BadResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
string $message,
RequestInterface $request,
ResponseInterface $response,
\Throwable $previous = null,
?\Throwable $previous = null,
array $handlerContext = []
) {
parent::__construct($message, $request, $response, $previous, $handlerContext);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ConnectException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ConnectException extends TransferException implements NetworkExceptionInte
public function __construct(
string $message,
RequestInterface $request,
\Throwable $previous = null,
?\Throwable $previous = null,
array $handlerContext = []
) {
parent::__construct($message, 0, $previous);
Expand Down
10 changes: 5 additions & 5 deletions src/Exception/RequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class RequestException extends TransferException implements RequestExceptionInte
public function __construct(
string $message,
RequestInterface $request,
ResponseInterface $response = null,
\Throwable $previous = null,
?ResponseInterface $response = null,
?\Throwable $previous = null,
array $handlerContext = []
) {
// Set the code of the exception if the response is set and not future.
Expand Down Expand Up @@ -63,10 +63,10 @@ public static function wrapException(RequestInterface $request, \Throwable $e):
*/
public static function create(
RequestInterface $request,
ResponseInterface $response = null,
\Throwable $previous = null,
?ResponseInterface $response = null,
?\Throwable $previous = null,
array $handlerContext = [],
BodySummarizerInterface $bodySummarizer = null
?BodySummarizerInterface $bodySummarizer = null
): self {
if (!$response) {
return new self(
Expand Down
8 changes: 4 additions & 4 deletions src/Handler/MockHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ class MockHandler implements \Countable
* @param callable|null $onFulfilled Callback to invoke when the return value is fulfilled.
* @param callable|null $onRejected Callback to invoke when the return value is rejected.
*/
public static function createWithMiddleware(array $queue = null, callable $onFulfilled = null, callable $onRejected = null): HandlerStack
public static function createWithMiddleware(?array $queue = null, ?callable $onFulfilled = null, ?callable $onRejected = null): HandlerStack
{
return HandlerStack::create(new self($queue, $onFulfilled, $onRejected));
}

/**
* The passed in value must be an array of
* {@see \Psr\Http\Message\ResponseInterface} objects, Exceptions,
* {@see ResponseInterface} objects, Exceptions,
* callables, or Promises.
*
* @param array<int, mixed>|null $queue The parameters to be passed to the append function, as an indexed array.
* @param callable|null $onFulfilled Callback to invoke when the return value is fulfilled.
* @param callable|null $onRejected Callback to invoke when the return value is rejected.
*/
public function __construct(array $queue = null, callable $onFulfilled = null, callable $onRejected = null)
public function __construct(?array $queue = null, ?callable $onFulfilled = null, ?callable $onRejected = null)
{
$this->onFulfilled = $onFulfilled;
$this->onRejected = $onRejected;
Expand Down Expand Up @@ -200,7 +200,7 @@ public function reset(): void
private function invokeStats(
RequestInterface $request,
array $options,
ResponseInterface $response = null,
?ResponseInterface $response = null,
$reason = null
): void {
if (isset($options['on_stats'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Handler/StreamHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ private function invokeStats(
array $options,
RequestInterface $request,
?float $startTime,
ResponseInterface $response = null,
\Throwable $error = null
?ResponseInterface $response = null,
?\Throwable $error = null
): void {
if (isset($options['on_stats'])) {
$stats = new TransferStats($request, $response, Utils::currentTime() - $startTime, $error, []);
Expand Down
6 changes: 3 additions & 3 deletions src/HandlerStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HandlerStack
* handler is provided, the best handler for your
* system will be utilized.
*/
public static function create(callable $handler = null): self
public static function create(?callable $handler = null): self
{
$stack = new self($handler ?: Utils::chooseHandler());
$stack->push(Middleware::httpErrors(), 'http_errors');
Expand All @@ -58,7 +58,7 @@ public static function create(callable $handler = null): self
/**
* @param (callable(RequestInterface, array): PromiseInterface)|null $handler Underlying HTTP handler.
*/
public function __construct(callable $handler = null)
public function __construct(?callable $handler = null)
{
$this->handler = $handler;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public function hasHandler(): bool
* @param callable(callable): callable $middleware Middleware function
* @param string $name Name to register for this middleware.
*/
public function unshift(callable $middleware, string $name = null): void
public function unshift(callable $middleware, ?string $name = null): void
{
\array_unshift($this->stack, [$middleware, $name]);
$this->cached = null;
Expand Down
2 changes: 1 addition & 1 deletion src/MessageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct(?string $template = self::CLF)
* @param ResponseInterface|null $response Response that was received
* @param \Throwable|null $error Exception that was received
*/
public function format(RequestInterface $request, ResponseInterface $response = null, \Throwable $error = null): string
public function format(RequestInterface $request, ?ResponseInterface $response = null, ?\Throwable $error = null): string
{
$cache = [];

Expand Down
2 changes: 1 addition & 1 deletion src/MessageFormatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ interface MessageFormatterInterface
* @param ResponseInterface|null $response Response that was received
* @param \Throwable|null $error Exception that was received
*/
public function format(RequestInterface $request, ResponseInterface $response = null, \Throwable $error = null): string;
public function format(RequestInterface $request, ?ResponseInterface $response = null, ?\Throwable $error = null): string;
}
6 changes: 3 additions & 3 deletions src/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static function (ResponseInterface $response) use ($cookieJar, $request): Respon
*
* @return callable(callable): callable Returns a function that accepts the next handler.
*/
public static function httpErrors(BodySummarizerInterface $bodySummarizer = null): callable
public static function httpErrors(?BodySummarizerInterface $bodySummarizer = null): callable
{
return static function (callable $handler) use ($bodySummarizer): callable {
return static function ($request, array $options) use ($handler, $bodySummarizer) {
Expand Down Expand Up @@ -132,7 +132,7 @@ static function ($reason) use ($request, &$container, $options) {
*
* @return callable Returns a function that accepts the next handler.
*/
public static function tap(callable $before = null, callable $after = null): callable
public static function tap(?callable $before = null, ?callable $after = null): callable
{
return static function (callable $handler) use ($before, $after): callable {
return static function (RequestInterface $request, array $options) use ($handler, $before, $after) {
Expand Down Expand Up @@ -176,7 +176,7 @@ public static function redirect(): callable
*
* @return callable Returns a function that accepts the next handler.
*/
public static function retry(callable $decider, callable $delay = null): callable
public static function retry(callable $decider, ?callable $delay = null): callable
{
return static function (callable $handler) use ($decider, $delay): RetryMiddleware {
return new RetryMiddleware($decider, $handler, $delay);
Expand Down
2 changes: 1 addition & 1 deletion src/RequestOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class RequestOptions
* Specifies whether or not cookies are used in a request or what cookie
* jar to use or what cookies to send. This option only works if your
* handler has the `cookie` middleware. Valid values are `false` and
* an instance of {@see \GuzzleHttp\Cookie\CookieJarInterface}.
* an instance of {@see Cookie\CookieJarInterface}.
*/
public const COOKIES = 'cookies';

Expand Down
4 changes: 2 additions & 2 deletions src/RetryMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RetryMiddleware
* and returns the number of
* milliseconds to delay.
*/
public function __construct(callable $decider, callable $nextHandler, callable $delay = null)
public function __construct(callable $decider, callable $nextHandler, ?callable $delay = null)
{
$this->decider = $decider;
$this->nextHandler = $nextHandler;
Expand Down Expand Up @@ -110,7 +110,7 @@ private function onRejected(RequestInterface $req, array $options): callable
};
}

private function doRetry(RequestInterface $request, array $options, ResponseInterface $response = null): PromiseInterface
private function doRetry(RequestInterface $request, array $options, ?ResponseInterface $response = null): PromiseInterface
{
$options['delay'] = ($this->delay)(++$options['retries'], $response, $request);

Expand Down
4 changes: 2 additions & 2 deletions src/TransferStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ final class TransferStats
*/
public function __construct(
RequestInterface $request,
ResponseInterface $response = null,
float $transferTime = null,
?ResponseInterface $response = null,
?float $transferTime = null,
$handlerErrorData = null,
array $handlerStats = []
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function debugResource($value = null)
return \STDOUT;
}

return \GuzzleHttp\Psr7\Utils::tryFopen('php://output', 'w');
return Psr7\Utils::tryFopen('php://output', 'w');
}

/**
Expand Down

0 comments on commit 3fe11f6

Please sign in to comment.