From 3fe11f6e104b37d49e935a1e913a732116be0b2b Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 31 Mar 2024 10:53:59 +0100 Subject: [PATCH] Fixes for PHP 8.4 deprecation --- .php-cs-fixer.dist.php | 1 + src/BodySummarizer.php | 6 +-- src/Client.php | 4 +- src/ClientInterface.php | 2 +- src/Cookie/CookieJar.php | 2 +- src/Cookie/CookieJarInterface.php | 2 +- src/Exception/BadResponseException.php | 2 +- src/Exception/ConnectException.php | 2 +- src/Exception/RequestException.php | 10 ++-- src/Handler/MockHandler.php | 8 +-- src/Handler/StreamHandler.php | 4 +- src/HandlerStack.php | 6 +-- src/MessageFormatter.php | 2 +- src/MessageFormatterInterface.php | 2 +- src/Middleware.php | 6 +-- src/RequestOptions.php | 2 +- src/RetryMiddleware.php | 4 +- src/TransferStats.php | 4 +- src/Utils.php | 2 +- tests/Handler/CurlFactoryTest.php | 72 +++++++++++++------------- tests/Handler/CurlHandlerTest.php | 4 +- tests/Handler/StreamHandlerTest.php | 12 ++--- tests/RedirectMiddlewareTest.php | 2 +- vendor-bin/php-cs-fixer/composer.json | 2 +- 24 files changed, 82 insertions(+), 81 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 800bad1ae..48dee7382 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -5,6 +5,7 @@ ->setRules([ '@PHP71Migration:risky' => true, '@PHPUnit75Migration:risky' => true, + '@PSR12:risky' => true, '@Symfony' => true, 'declare_strict_types' => false, 'global_namespace_import' => false, diff --git a/src/BodySummarizer.php b/src/BodySummarizer.php index 6eca94ef9..761506dd0 100644 --- a/src/BodySummarizer.php +++ b/src/BodySummarizer.php @@ -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; } @@ -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); } } diff --git a/src/Client.php b/src/Client.php index bc6efc90f..c78919a4f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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 = []) { @@ -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 diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 1788e16ab..6aaee61af 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -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); } diff --git a/src/Cookie/CookieJar.php b/src/Cookie/CookieJar.php index c29b4b7e9..b616cf2ed 100644 --- a/src/Cookie/CookieJar.php +++ b/src/Cookie/CookieJar.php @@ -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 = []; diff --git a/src/Cookie/CookieJarInterface.php b/src/Cookie/CookieJarInterface.php index 8c55cc6f7..93ada58d2 100644 --- a/src/Cookie/CookieJarInterface.php +++ b/src/Cookie/CookieJarInterface.php @@ -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. diff --git a/src/Exception/BadResponseException.php b/src/Exception/BadResponseException.php index a80956c9d..ba67ad498 100644 --- a/src/Exception/BadResponseException.php +++ b/src/Exception/BadResponseException.php @@ -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); diff --git a/src/Exception/ConnectException.php b/src/Exception/ConnectException.php index e1a31519c..eab51ca17 100644 --- a/src/Exception/ConnectException.php +++ b/src/Exception/ConnectException.php @@ -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); diff --git a/src/Exception/RequestException.php b/src/Exception/RequestException.php index c2d0a9ccc..ae05ccfa1 100644 --- a/src/Exception/RequestException.php +++ b/src/Exception/RequestException.php @@ -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. @@ -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( diff --git a/src/Handler/MockHandler.php b/src/Handler/MockHandler.php index 77ffed521..3ecd5964d 100644 --- a/src/Handler/MockHandler.php +++ b/src/Handler/MockHandler.php @@ -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|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; @@ -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'])) { diff --git a/src/Handler/StreamHandler.php b/src/Handler/StreamHandler.php index 61632f564..baae465c2 100644 --- a/src/Handler/StreamHandler.php +++ b/src/Handler/StreamHandler.php @@ -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, []); diff --git a/src/HandlerStack.php b/src/HandlerStack.php index 6cb12f07a..03f9a18ff 100644 --- a/src/HandlerStack.php +++ b/src/HandlerStack.php @@ -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'); @@ -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; } @@ -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; diff --git a/src/MessageFormatter.php b/src/MessageFormatter.php index 04e9eb37a..9b77eee83 100644 --- a/src/MessageFormatter.php +++ b/src/MessageFormatter.php @@ -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 = []; diff --git a/src/MessageFormatterInterface.php b/src/MessageFormatterInterface.php index 47934614a..a39ac248e 100644 --- a/src/MessageFormatterInterface.php +++ b/src/MessageFormatterInterface.php @@ -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; } diff --git a/src/Middleware.php b/src/Middleware.php index 7e3eb6b3a..6edbb3fe4 100644 --- a/src/Middleware.php +++ b/src/Middleware.php @@ -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) { @@ -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) { @@ -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); diff --git a/src/RequestOptions.php b/src/RequestOptions.php index a38768c0c..84a3500e4 100644 --- a/src/RequestOptions.php +++ b/src/RequestOptions.php @@ -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'; diff --git a/src/RetryMiddleware.php b/src/RetryMiddleware.php index 8f4d93ac4..65f49cb75 100644 --- a/src/RetryMiddleware.php +++ b/src/RetryMiddleware.php @@ -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; @@ -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); diff --git a/src/TransferStats.php b/src/TransferStats.php index 2ce9e38f2..93fa334c8 100644 --- a/src/TransferStats.php +++ b/src/TransferStats.php @@ -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 = [] ) { diff --git a/src/Utils.php b/src/Utils.php index 93d6d39cd..140cb6fe5 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -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'); } /** diff --git a/tests/Handler/CurlFactoryTest.php b/tests/Handler/CurlFactoryTest.php index af88b0966..a5b8f3f68 100644 --- a/tests/Handler/CurlFactoryTest.php +++ b/tests/Handler/CurlFactoryTest.php @@ -46,7 +46,7 @@ public function testCreatesCurlHandle() 'Hi' => ' 123', 'Content-Length' => '7', ], 'testing'); - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $result = $f->create($request, ['sink' => $stream]); self::assertInstanceOf(EasyHandle::class, $result); if (\PHP_VERSION_ID >= 80000) { @@ -118,7 +118,7 @@ public function testCanChangeCurlOptions() public function testValidatesVerify() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('SSL CA bundle not found: /does/not/exist'); @@ -127,7 +127,7 @@ public function testValidatesVerify() public function testCanSetVerifyToFile() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', 'http://foo.com'), ['verify' => __FILE__]); self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_CAINFO]); self::assertEquals(2, $_SERVER['_curl'][\CURLOPT_SSL_VERIFYHOST]); @@ -136,7 +136,7 @@ public function testCanSetVerifyToFile() public function testCanSetVerifyToDir() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', 'http://foo.com'), ['verify' => __DIR__]); self::assertEquals(__DIR__, $_SERVER['_curl'][\CURLOPT_CAPATH]); self::assertEquals(2, $_SERVER['_curl'][\CURLOPT_SSL_VERIFYHOST]); @@ -145,7 +145,7 @@ public function testCanSetVerifyToDir() public function testAddsVerifyAsTrue() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['verify' => true]); self::assertEquals(2, $_SERVER['_curl'][\CURLOPT_SSL_VERIFYHOST]); self::assertTrue($_SERVER['_curl'][\CURLOPT_SSL_VERIFYPEER]); @@ -154,7 +154,7 @@ public function testAddsVerifyAsTrue() public function testCanDisableVerify() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['verify' => false]); self::assertEquals(0, $_SERVER['_curl'][\CURLOPT_SSL_VERIFYHOST]); self::assertFalse($_SERVER['_curl'][\CURLOPT_SSL_VERIFYPEER]); @@ -162,14 +162,14 @@ public function testCanDisableVerify() public function testAddsProxy() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['proxy' => 'http://bar.com']); self::assertEquals('http://bar.com', $_SERVER['_curl'][\CURLOPT_PROXY]); } public function testAddsViaScheme() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), [ 'proxy' => ['http' => 'http://bar.com', 'https' => 'https://t'], ]); @@ -183,7 +183,7 @@ public function testAddsViaScheme() private function checkNoProxyForHost($url, $noProxy, $assertUseProxy) { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', $url), [ 'proxy' => [ 'http' => 'http://bar.com', @@ -223,7 +223,7 @@ public function testUsesProxy() public function testValidatesCryptoMethodInvalidMethod() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid crypto_method request option: unknown version provided'); @@ -232,21 +232,21 @@ public function testValidatesCryptoMethodInvalidMethod() public function testAddsCryptoMethodTls10() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['crypto_method' => \STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT]); self::assertEquals(\CURL_SSLVERSION_TLSv1_0, $_SERVER['_curl'][\CURLOPT_SSLVERSION]); } public function testAddsCryptoMethodTls11() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['crypto_method' => \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT]); self::assertEquals(\CURL_SSLVERSION_TLSv1_1, $_SERVER['_curl'][\CURLOPT_SSLVERSION]); } public function testAddsCryptoMethodTls12() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['crypto_method' => \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT]); self::assertEquals(\CURL_SSLVERSION_TLSv1_2, $_SERVER['_curl'][\CURLOPT_SSLVERSION]); } @@ -256,14 +256,14 @@ public function testAddsCryptoMethodTls12() */ public function testAddsCryptoMethodTls13() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['crypto_method' => \STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]); self::assertEquals(\CURL_SSLVERSION_TLSv1_3, $_SERVER['_curl'][\CURLOPT_SSLVERSION]); } public function testValidatesSslKey() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('SSL private key not found: /does/not/exist'); @@ -272,14 +272,14 @@ public function testValidatesSslKey() public function testAddsSslKey() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['ssl_key' => __FILE__]); self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_SSLKEY]); } public function testAddsSslKeyWithPassword() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['ssl_key' => [__FILE__, 'test']]); self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_SSLKEY]); self::assertEquals('test', $_SERVER['_curl'][\CURLOPT_SSLKEYPASSWD]); @@ -287,7 +287,7 @@ public function testAddsSslKeyWithPassword() public function testAddsSslKeyWhenUsingArraySyntaxButNoPassword() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['ssl_key' => [__FILE__]]); self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_SSLKEY]); @@ -295,7 +295,7 @@ public function testAddsSslKeyWhenUsingArraySyntaxButNoPassword() public function testValidatesCert() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('SSL certificate not found: /does/not/exist'); @@ -304,14 +304,14 @@ public function testValidatesCert() public function testAddsCert() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['cert' => __FILE__]); self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_SSLCERT]); } public function testAddsCertWithPassword() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['cert' => [__FILE__, 'test']]); self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_SSLCERT]); self::assertEquals('test', $_SERVER['_curl'][\CURLOPT_SSLCERTPASSWD]); @@ -322,7 +322,7 @@ public function testAddsDerCert() $certFile = tempnam(sys_get_temp_dir(), 'mock_test_cert'); rename($certFile, $certFile .= '.der'); try { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['cert' => $certFile]); self::assertArrayHasKey(\CURLOPT_SSLCERTTYPE, $_SERVER['_curl']); self::assertEquals('DER', $_SERVER['_curl'][\CURLOPT_SSLCERTTYPE]); @@ -336,7 +336,7 @@ public function testAddsP12Cert() $certFile = tempnam(sys_get_temp_dir(), 'mock_test_cert'); rename($certFile, $certFile .= '.p12'); try { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), ['cert' => $certFile]); self::assertArrayHasKey(\CURLOPT_SSLCERTTYPE, $_SERVER['_curl']); self::assertEquals('P12', $_SERVER['_curl'][\CURLOPT_SSLCERTTYPE]); @@ -347,7 +347,7 @@ public function testAddsP12Cert() public function testValidatesProgress() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('progress client option must be callable'); @@ -566,7 +566,7 @@ public function testSendsPostWithNoBodyOrDefaultContentType() public function testFailsWhenCannotRewindRetryAfterNoResponse() { - $factory = new Handler\CurlFactory(1); + $factory = new CurlFactory(1); $stream = Psr7\Utils::streamFor('abc'); $stream->read(1); $stream = new Psr7\NoSeekStream($stream); @@ -574,7 +574,7 @@ public function testFailsWhenCannotRewindRetryAfterNoResponse() $fn = static function ($request, $options) use (&$fn, $factory) { $easy = $factory->create($request, $options); - return Handler\CurlFactory::finish($fn, $easy, $factory); + return CurlFactory::finish($fn, $easy, $factory); }; $this->expectException(RequestException::class); @@ -601,10 +601,10 @@ public function testRetriesWhenBodyCanBeRewound() }, ]); - $factory = new Handler\CurlFactory(1); + $factory = new CurlFactory(1); $req = new Psr7\Request('PUT', Server::$url, [], $bd); $easy = $factory->create($req, []); - $res = Handler\CurlFactory::finish($fn, $easy, $factory); + $res = CurlFactory::finish($fn, $easy, $factory); $res = $res->wait(); self::assertTrue($callHandler); self::assertTrue($called); @@ -613,13 +613,13 @@ public function testRetriesWhenBodyCanBeRewound() public function testFailsWhenRetryMoreThanThreeTimes() { - $factory = new Handler\CurlFactory(1); + $factory = new CurlFactory(1); $call = 0; $fn = static function ($request, $options) use (&$mock, &$call, $factory) { ++$call; $easy = $factory->create($request, $options); - return Handler\CurlFactory::finish($mock, $easy, $factory); + return CurlFactory::finish($mock, $easy, $factory); }; $mock = new Handler\MockHandler([$fn, $fn, $fn]); $p = $mock(new Psr7\Request('PUT', Server::$url, [], 'test'), []); @@ -653,7 +653,7 @@ public function testCreatesConnectException() { $m = new \ReflectionMethod(CurlFactory::class, 'finishError'); $m->setAccessible(true); - $factory = new Handler\CurlFactory(1); + $factory = new CurlFactory(1); $easy = $factory->create(new Psr7\Request('GET', Server::$url), []); $easy->errno = \CURLE_COULDNT_CONNECT; $response = $m->invoke( @@ -670,7 +670,7 @@ static function () { public function testAddsTimeouts() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $f->create(new Psr7\Request('GET', Server::$url), [ 'timeout' => 0.1, 'connect_timeout' => 0.2, @@ -681,7 +681,7 @@ public function testAddsTimeouts() public function testAddsStreamingBody() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $bd = Psr7\FnStream::decorate(Psr7\Utils::streamFor('foo'), [ 'getSize' => static function () { return null; @@ -695,7 +695,7 @@ public function testAddsStreamingBody() public function testEnsuresDirExistsBeforeThrowingWarning() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Directory /does/not/exist/so does not exist for sink value of /does/not/exist/so/error.txt'); @@ -706,7 +706,7 @@ public function testEnsuresDirExistsBeforeThrowingWarning() public function testClosesIdleHandles() { - $f = new Handler\CurlFactory(3); + $f = new CurlFactory(3); $req = new Psr7\Request('GET', Server::$url); $easy = $f->create($req, []); $h1 = $easy->handle; @@ -736,7 +736,7 @@ public function testRejectsPromiseWhenCreateResponseFails() $handler = new Handler\CurlHandler(); $promise = $handler($req, []); - $this->expectException(\GuzzleHttp\Exception\RequestException::class); + $this->expectException(RequestException::class); $this->expectExceptionMessage('An error was encountered while creating the response'); $promise->wait(); } diff --git a/tests/Handler/CurlHandlerTest.php b/tests/Handler/CurlHandlerTest.php index df20a236e..b9e11f682 100644 --- a/tests/Handler/CurlHandlerTest.php +++ b/tests/Handler/CurlHandlerTest.php @@ -35,7 +35,7 @@ public function testCreatesCurlErrors() public function testReusesHandles() { Server::flush(); - $response = new response(200); + $response = new Response(200); Server::enqueue([$response, $response]); $a = new CurlHandler(); $request = new Request('GET', Server::$url); @@ -45,7 +45,7 @@ public function testReusesHandles() public function testDoesSleep() { - $response = new response(200); + $response = new Response(200); Server::enqueue([$response]); $a = new CurlHandler(); $request = new Request('GET', Server::$url); diff --git a/tests/Handler/StreamHandlerTest.php b/tests/Handler/StreamHandlerTest.php index 2d02b5ec5..725e6910f 100644 --- a/tests/Handler/StreamHandlerTest.php +++ b/tests/Handler/StreamHandlerTest.php @@ -570,7 +570,7 @@ public function testSupports100Continue() public function testDoesSleep() { - $response = new response(200); + $response = new Response(200); Server::enqueue([$response]); $a = new StreamHandler(); $request = new Request('GET', Server::$url); @@ -643,8 +643,8 @@ public function testSuccessfullyCallsOnHeadersBeforeWritingToSink() public function testInvokesOnStatsOnSuccess() { Server::flush(); - Server::enqueue([new Psr7\Response(200)]); - $req = new Psr7\Request('GET', Server::$url); + Server::enqueue([new Response(200)]); + $req = new Request('GET', Server::$url); $gotStats = null; $handler = new StreamHandler(); $promise = $handler($req, [ @@ -668,7 +668,7 @@ public function testInvokesOnStatsOnSuccess() public function testInvokesOnStatsOnError() { - $req = new Psr7\Request('GET', 'http://127.0.0.1:123'); + $req = new Request('GET', 'http://127.0.0.1:123'); $gotStats = null; $handler = new StreamHandler(); $promise = $handler($req, [ @@ -698,8 +698,8 @@ public function testInvokesOnStatsOnError() public function testStreamIgnoresZeroTimeout() { Server::flush(); - Server::enqueue([new Psr7\Response(200)]); - $req = new Psr7\Request('GET', Server::$url); + Server::enqueue([new Response(200)]); + $req = new Request('GET', Server::$url); $gotStats = null; $handler = new StreamHandler(); $promise = $handler($req, [ diff --git a/tests/RedirectMiddlewareTest.php b/tests/RedirectMiddlewareTest.php index 2bd355fb0..5dbe8bd7d 100644 --- a/tests/RedirectMiddlewareTest.php +++ b/tests/RedirectMiddlewareTest.php @@ -113,7 +113,7 @@ public function testTooManyRedirectsExceptionHasResponse() try { $promise->wait(); self::fail(); - } catch (\GuzzleHttp\Exception\TooManyRedirectsException $e) { + } catch (TooManyRedirectsException $e) { self::assertSame(302, $e->getResponse()->getStatusCode()); } } diff --git a/vendor-bin/php-cs-fixer/composer.json b/vendor-bin/php-cs-fixer/composer.json index 3e8c9dfbb..049eacf10 100644 --- a/vendor-bin/php-cs-fixer/composer.json +++ b/vendor-bin/php-cs-fixer/composer.json @@ -1,7 +1,7 @@ { "require": { "php": "^7.4 || ^8.0", - "friendsofphp/php-cs-fixer": "3.40.2" + "friendsofphp/php-cs-fixer": "3.52.1" }, "config": { "preferred-install": "dist"