mirror of
https://github.com/symfony/http-client.git
synced 2026-03-24 00:12:11 +01:00
PHP CS Fixer: enable static_lambda
This commit is contained in:
committed by
Nicolas Grekas
parent
9ae8392b30
commit
dc7ca8a8cd
@@ -697,11 +697,11 @@ trait HttpClientTrait
|
||||
|
||||
if (str_contains($parts[$part], '%')) {
|
||||
// https://tools.ietf.org/html/rfc3986#section-2.3
|
||||
$parts[$part] = preg_replace_callback('/%(?:2[DE]|3[0-9]|[46][1-9A-F]|5F|[57][0-9A]|7E)++/i', fn ($m) => rawurldecode($m[0]), $parts[$part]);
|
||||
$parts[$part] = preg_replace_callback('/%(?:2[DE]|3[0-9]|[46][1-9A-F]|5F|[57][0-9A]|7E)++/i', static fn ($m) => rawurldecode($m[0]), $parts[$part]);
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc3986#section-3.3
|
||||
$parts[$part] = preg_replace_callback("#[^-A-Za-z0-9._~!$&/'()[\]*+,;=:@{}%]++#", fn ($m) => rawurlencode($m[0]), $parts[$part]);
|
||||
$parts[$part] = preg_replace_callback("#[^-A-Za-z0-9._~!$&/'()[\]*+,;=:@{}%]++#", static fn ($m) => rawurlencode($m[0]), $parts[$part]);
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
@@ -188,7 +188,7 @@ final class AmpResponse implements ResponseInterface, StreamableInterface
|
||||
$delay = new DeferredFuture();
|
||||
$id = EventLoop::delay($timeout, $delay->complete(...));
|
||||
|
||||
awaitFirst((function () use ($delay, $multi) {
|
||||
awaitFirst((static function () use ($delay, $multi) {
|
||||
yield $delay->getFuture();
|
||||
|
||||
foreach ($multi->openHandles as $deferred) {
|
||||
|
||||
@@ -181,7 +181,7 @@ class AsyncDecoratorTraitTest extends NativeHttpClientTest
|
||||
public function testProcessingHappensOnce()
|
||||
{
|
||||
$lastChunks = 0;
|
||||
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) use (&$lastChunks) {
|
||||
$client = $this->getHttpClient(__FUNCTION__, static function (ChunkInterface $chunk, AsyncContext $context) use (&$lastChunks) {
|
||||
$lastChunks += $chunk->isLast();
|
||||
|
||||
yield $chunk;
|
||||
@@ -204,7 +204,7 @@ class AsyncDecoratorTraitTest extends NativeHttpClientTest
|
||||
public function testLastChunkIsYieldOnHttpExceptionAtDestructTime()
|
||||
{
|
||||
$lastChunk = null;
|
||||
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) use (&$lastChunk) {
|
||||
$client = $this->getHttpClient(__FUNCTION__, static function (ChunkInterface $chunk, AsyncContext $context) use (&$lastChunk) {
|
||||
$lastChunk = $chunk;
|
||||
|
||||
yield $chunk;
|
||||
@@ -221,7 +221,7 @@ class AsyncDecoratorTraitTest extends NativeHttpClientTest
|
||||
|
||||
public function testBufferPurePassthru()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) {
|
||||
$client = $this->getHttpClient(__FUNCTION__, static function (ChunkInterface $chunk, AsyncContext $context) {
|
||||
$context->passthru();
|
||||
|
||||
yield $chunk;
|
||||
@@ -297,10 +297,10 @@ class AsyncDecoratorTraitTest extends NativeHttpClientTest
|
||||
public function testInfoPassToDecorator()
|
||||
{
|
||||
$lastInfo = null;
|
||||
$options = ['on_progress' => function (int $dlNow, int $dlSize, array $info) use (&$lastInfo) {
|
||||
$options = ['on_progress' => static function (int $dlNow, int $dlSize, array $info) use (&$lastInfo) {
|
||||
$lastInfo = $info;
|
||||
}];
|
||||
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) use ($options) {
|
||||
$client = $this->getHttpClient(__FUNCTION__, static function (ChunkInterface $chunk, AsyncContext $context) use ($options) {
|
||||
$context->setInfo('foo', 'test');
|
||||
$context->getResponse()->cancel();
|
||||
$context->replaceRequest('GET', 'http://localhost:8057/', $options);
|
||||
@@ -315,7 +315,7 @@ class AsyncDecoratorTraitTest extends NativeHttpClientTest
|
||||
|
||||
public function testMultipleYieldInInitializer()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) {
|
||||
$client = $this->getHttpClient(__FUNCTION__, static function (ChunkInterface $chunk, AsyncContext $context) {
|
||||
static $first;
|
||||
if ($chunk->isFirst()) {
|
||||
$first = $chunk;
|
||||
@@ -357,7 +357,7 @@ class AsyncDecoratorTraitTest extends NativeHttpClientTest
|
||||
|
||||
public function testMaxDuration()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) {
|
||||
$client = $this->getHttpClient(__FUNCTION__, static function (ChunkInterface $chunk, AsyncContext $context) {
|
||||
static $sawFirst = false;
|
||||
try {
|
||||
if (!$chunk->isFirst() || !$sawFirst) {
|
||||
|
||||
@@ -485,7 +485,7 @@ class HttpClientDataCollectorTest extends TestCase
|
||||
public static function provideClientIsResetWhenExpectedCases(): iterable
|
||||
{
|
||||
yield [
|
||||
function (TraceableHttpClient $traceableHttpClient) {
|
||||
static function (TraceableHttpClient $traceableHttpClient) {
|
||||
$response = $traceableHttpClient->request('GET', 'http://localhost/');
|
||||
$response->getContent();
|
||||
},
|
||||
@@ -493,7 +493,7 @@ class HttpClientDataCollectorTest extends TestCase
|
||||
];
|
||||
|
||||
yield [
|
||||
fn () => null,
|
||||
static fn () => null,
|
||||
false,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ class EventSourceHttpClientTest extends TestCase
|
||||
{
|
||||
$chunk = new DataChunk(0, '');
|
||||
$response = new MockResponse('', ['canceled' => false, 'http_method' => 'POST', 'url' => 'http://localhost:8080/events', 'response_headers' => ['content-type: text/event-stream']]);
|
||||
$responseStream = new ResponseStream((function () use ($response, $chunk) {
|
||||
$responseStream = new ResponseStream((static function () use ($response, $chunk) {
|
||||
yield $response => new FirstChunk();
|
||||
yield $response => $chunk;
|
||||
yield $response => new ErrorChunk(0, 'timeout');
|
||||
@@ -140,7 +140,7 @@ class EventSourceHttpClientTest extends TestCase
|
||||
{
|
||||
$chunk = new DataChunk(0, '');
|
||||
$response = new MockResponse('', ['canceled' => false, 'http_method' => 'GET', 'url' => 'http://localhost:8080/events', 'response_headers' => ['content-type: '.$contentType]]);
|
||||
$responseStream = new ResponseStream((function () use ($response, $chunk) {
|
||||
$responseStream = new ResponseStream((static function () use ($response, $chunk) {
|
||||
yield $response => new FirstChunk();
|
||||
yield $response => $chunk;
|
||||
yield $response => new ErrorChunk(0, 'timeout');
|
||||
|
||||
@@ -384,7 +384,7 @@ abstract class HttpClientTestCase extends BaseHttpClientTestCase
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
|
||||
$traceInfo = [];
|
||||
$client->request('GET', 'http://localhost:8057', ['on_progress' => function (int $dlNow, int $dlSize, array $info) use (&$traceInfo) {
|
||||
$client->request('GET', 'http://localhost:8057', ['on_progress' => static function (int $dlNow, int $dlSize, array $info) use (&$traceInfo) {
|
||||
$traceInfo = $info;
|
||||
}]);
|
||||
|
||||
@@ -665,7 +665,7 @@ abstract class HttpClientTestCase extends BaseHttpClientTestCase
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
|
||||
$response = $client->request('HEAD', 'http://localhost:8057/head', [
|
||||
'body' => fn () => '',
|
||||
'body' => static fn () => '',
|
||||
]);
|
||||
$headers = $response->getHeaders();
|
||||
} finally {
|
||||
|
||||
@@ -56,11 +56,11 @@ class HttplugClientTest extends TestCase
|
||||
$promise = $client->sendAsyncRequest($client->createRequest('GET', 'http://localhost:8057'));
|
||||
$successCallableCalled = false;
|
||||
$failureCallableCalled = false;
|
||||
$promise->then(function (ResponseInterface $response) use (&$successCallableCalled) {
|
||||
$promise->then(static function (ResponseInterface $response) use (&$successCallableCalled) {
|
||||
$successCallableCalled = true;
|
||||
|
||||
return $response;
|
||||
}, function (\Exception $exception) use (&$failureCallableCalled) {
|
||||
}, static function (\Exception $exception) use (&$failureCallableCalled) {
|
||||
$failureCallableCalled = true;
|
||||
|
||||
throw $exception;
|
||||
@@ -88,11 +88,11 @@ class HttplugClientTest extends TestCase
|
||||
$successCallableCalled = false;
|
||||
$failureCallableCalled = false;
|
||||
$client->sendAsyncRequest($client->createRequest('GET', 'http://localhost:8057/timeout-body'))
|
||||
->then(function (ResponseInterface $response) use (&$successCallableCalled) {
|
||||
->then(static function (ResponseInterface $response) use (&$successCallableCalled) {
|
||||
$successCallableCalled = true;
|
||||
|
||||
return $response;
|
||||
}, function (\Exception $exception) use (&$failureCallableCalled) {
|
||||
}, static function (\Exception $exception) use (&$failureCallableCalled) {
|
||||
$failureCallableCalled = true;
|
||||
|
||||
throw $exception;
|
||||
@@ -134,11 +134,11 @@ class HttplugClientTest extends TestCase
|
||||
$promise = $client->sendAsyncRequest($client->createRequest('GET', 'http://localhost:8058'));
|
||||
$successCallableCalled = false;
|
||||
$failureCallableCalled = false;
|
||||
$promise->then(function (ResponseInterface $response) use (&$successCallableCalled) {
|
||||
$promise->then(static function (ResponseInterface $response) use (&$successCallableCalled) {
|
||||
$successCallableCalled = true;
|
||||
|
||||
return $response;
|
||||
}, function (\Exception $exception) use (&$failureCallableCalled) {
|
||||
}, static function (\Exception $exception) use (&$failureCallableCalled) {
|
||||
$failureCallableCalled = true;
|
||||
|
||||
throw $exception;
|
||||
@@ -177,7 +177,7 @@ class HttplugClientTest extends TestCase
|
||||
|
||||
return $client->sendAsyncRequest($client->createRequest('GET', 'http://localhost:8057'));
|
||||
},
|
||||
function (\Exception $exception) use (&$failureCallableCalled) {
|
||||
static function (\Exception $exception) use (&$failureCallableCalled) {
|
||||
$failureCallableCalled = true;
|
||||
|
||||
throw $exception;
|
||||
@@ -201,7 +201,7 @@ class HttplugClientTest extends TestCase
|
||||
|
||||
$promise = $client
|
||||
->sendAsyncRequest($client->createRequest('GET', 'http://localhost:8057/chunked-broken'))
|
||||
->then(function (ResponseInterface $response) use (&$successCallableCalled) {
|
||||
->then(static function (ResponseInterface $response) use (&$successCallableCalled) {
|
||||
$successCallableCalled = true;
|
||||
|
||||
return $response;
|
||||
@@ -226,7 +226,7 @@ class HttplugClientTest extends TestCase
|
||||
$isFirstRequest = true;
|
||||
$errorMessage = 'Error occurred before making the actual request.';
|
||||
|
||||
$client = new HttplugClient(new MockHttpClient(function () use (&$isFirstRequest, $errorMessage) {
|
||||
$client = new HttplugClient(new MockHttpClient(static function () use (&$isFirstRequest, $errorMessage) {
|
||||
if ($isFirstRequest) {
|
||||
$isFirstRequest = false;
|
||||
throw new TransportException($errorMessage);
|
||||
@@ -243,7 +243,7 @@ class HttplugClientTest extends TestCase
|
||||
$promise = $client
|
||||
->sendAsyncRequest($request)
|
||||
->then(
|
||||
function (ResponseInterface $response) use (&$successCallableCalled) {
|
||||
static function (ResponseInterface $response) use (&$successCallableCalled) {
|
||||
$successCallableCalled = true;
|
||||
|
||||
return $response;
|
||||
@@ -254,7 +254,7 @@ class HttplugClientTest extends TestCase
|
||||
$failureCallableCalled = true;
|
||||
|
||||
// Ensure arbitrary levels of promises work.
|
||||
return (new FulfilledPromise(null))->then(fn () => (new GuzzleFulfilledPromise(null))->then(fn () => $client->sendAsyncRequest($request)));
|
||||
return (new FulfilledPromise(null))->then(static fn () => (new GuzzleFulfilledPromise(null))->then(static fn () => $client->sendAsyncRequest($request)));
|
||||
}
|
||||
)
|
||||
;
|
||||
@@ -302,7 +302,7 @@ class HttplugClientTest extends TestCase
|
||||
|
||||
public function testAutoUpgradeHttpVersion()
|
||||
{
|
||||
$clientWithoutOption = new HttplugClient(new MockHttpClient(function (string $method, string $url, array $options) {
|
||||
$clientWithoutOption = new HttplugClient(new MockHttpClient(static function (string $method, string $url, array $options) {
|
||||
return new MockResponse(json_encode([
|
||||
'SERVER_PROTOCOL' => 'HTTP/'.$options['http_version'] ?? '',
|
||||
]), [
|
||||
|
||||
@@ -420,7 +420,7 @@ class MockHttpClientTest extends HttpClientTestCase
|
||||
case 'testResolve':
|
||||
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
|
||||
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
|
||||
$responses[] = new MockResponse((function () { yield ''; })(), ['response_headers' => $headers]);
|
||||
$responses[] = new MockResponse((static function () { yield ''; })(), ['response_headers' => $headers]);
|
||||
break;
|
||||
|
||||
case 'testTimeoutOnStream':
|
||||
@@ -468,7 +468,7 @@ class MockHttpClientTest extends HttpClientTestCase
|
||||
case 'testNonBlockingStream':
|
||||
case 'testSeekAsyncStream':
|
||||
$responses[] = new MockResponse(
|
||||
(function () {
|
||||
(static function () {
|
||||
yield '<1>';
|
||||
yield '';
|
||||
yield '<2>';
|
||||
|
||||
@@ -145,7 +145,7 @@ class NoPrivateNetworkHttpClientTest extends TestCase
|
||||
$content = 'foo';
|
||||
|
||||
$executionCount = 0;
|
||||
$customCallback = function (int $dlNow, int $dlSize, array $info) use (&$executionCount): void {
|
||||
$customCallback = static function (int $dlNow, int $dlSize, array $info) use (&$executionCount): void {
|
||||
++$executionCount;
|
||||
};
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ class Psr18ClientTest extends TestCase
|
||||
|
||||
public function testAutoUpgradeHttpVersion()
|
||||
{
|
||||
$clientWithoutOption = new Psr18Client(new MockHttpClient(function (string $method, string $url, array $options) {
|
||||
$clientWithoutOption = new Psr18Client(new MockHttpClient(static function (string $method, string $url, array $options) {
|
||||
return new MockResponse(json_encode([
|
||||
'SERVER_PROTOCOL' => 'HTTP/'.$options['http_version'] ?? '',
|
||||
]), [
|
||||
|
||||
@@ -19,8 +19,8 @@ class HttplugPromiseTest extends TestCase
|
||||
{
|
||||
public function testComplexNesting()
|
||||
{
|
||||
$mkPromise = function ($result): HttplugPromise {
|
||||
$guzzlePromise = new Promise(function () use (&$guzzlePromise, $result) {
|
||||
$mkPromise = static function ($result): HttplugPromise {
|
||||
$guzzlePromise = new Promise(static function () use (&$guzzlePromise, $result) {
|
||||
$guzzlePromise->resolve($result);
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ class HttplugPromiseTest extends TestCase
|
||||
|
||||
$promise1 = $mkPromise('result');
|
||||
$promise2 = $promise1->then($mkPromise);
|
||||
$promise3 = $promise2->then(fn ($result) => $result);
|
||||
$promise3 = $promise2->then(static fn ($result) => $result);
|
||||
|
||||
$this->assertSame('result', $promise3->wait());
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class ThrottlingHttpClientTest extends TestCase
|
||||
self::fail(\sprintf('The pause handler should\'t have been called, but it was called with %f.', $duration));
|
||||
};
|
||||
|
||||
$pauseHandler = static fn (float $expectedDuration) => function (float $duration) use ($expectedDuration) {
|
||||
$pauseHandler = static fn (float $expectedDuration) => static function (float $duration) use ($expectedDuration) {
|
||||
self::assertEqualsWithDelta($expectedDuration, $duration, 1);
|
||||
};
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ class TraceableHttpClientTest extends TestCase
|
||||
{
|
||||
$sut = new TraceableHttpClient(new MockHttpClient());
|
||||
$foo = 0;
|
||||
$sut->request('GET', 'http://localhost:8057', ['on_progress' => function (int $dlNow, int $dlSize, array $info) use (&$foo) {
|
||||
$sut->request('GET', 'http://localhost:8057', ['on_progress' => static function (int $dlNow, int $dlSize, array $info) use (&$foo) {
|
||||
++$foo;
|
||||
}]);
|
||||
$this->assertCount(1, $tracedRequests = $sut->getTracedRequests());
|
||||
@@ -123,7 +123,7 @@ class TraceableHttpClientTest extends TestCase
|
||||
{
|
||||
$this->expectException(ClientExceptionInterface::class);
|
||||
|
||||
$sut = new TraceableHttpClient(new MockHttpClient($responseFactory = fn (): MockResponse => new MockResponse('Errored.', ['http_code' => 400])));
|
||||
$sut = new TraceableHttpClient(new MockHttpClient($responseFactory = static fn (): MockResponse => new MockResponse('Errored.', ['http_code' => 400])));
|
||||
|
||||
$response = $sut->request('GET', 'https://example.com/foo/bar');
|
||||
$response->toArray();
|
||||
|
||||
@@ -58,7 +58,7 @@ final class TraceableHttpClient implements HttpClientInterface, ResetInterface
|
||||
}
|
||||
$this->tracedRequests[] = $tracedRequest;
|
||||
|
||||
$options['on_progress'] = function (int $dlNow, int $dlSize, array $info) use (&$traceInfo, $onProgress) {
|
||||
$options['on_progress'] = static function (int $dlNow, int $dlSize, array $info) use (&$traceInfo, $onProgress) {
|
||||
$traceInfo = $info;
|
||||
|
||||
if (null !== $onProgress) {
|
||||
|
||||
Reference in New Issue
Block a user