Skip to content

Commit 89541fa

Browse files
committed
refactor: Add ArrowFunction return type #1183
1 parent 7ce7184 commit 89541fa

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/Header/AcceptHeader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getAll(): array
7878
/**
7979
* Sort item in descending order.
8080
*/
81-
\uasort($this->items, static fn (AcceptHeaderItem $a, AcceptHeaderItem $b) => self::compare($a, $b) * -1);
81+
\uasort($this->items, static fn (AcceptHeaderItem $a, AcceptHeaderItem $b): int => self::compare($a, $b) * -1);
8282

8383
$this->sorted = true;
8484
}

tests/HttpTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testRunHandler(): void
4747
{
4848
$core = $this->getCore();
4949

50-
$core->setHandler(fn() => 'hello world');
50+
$core->setHandler(fn(): string => 'hello world');
5151

5252
$response = $core->handle(new ServerRequest('GET', ''));
5353
$this->assertSame('hello world', (string)$response->getBody());
@@ -67,7 +67,7 @@ public function testHandlerInterface(): void
6767
{
6868
$core = $this->getCore();
6969
$core->setHandler(
70-
new CallableHandler(fn() => 'hello world', new ResponseFactory(new HttpConfig(['headers' => []])))
70+
new CallableHandler(fn(): string => 'hello world', new ResponseFactory(new HttpConfig(['headers' => []])))
7171
);
7272

7373
$response = $core->handle(new ServerRequest('GET', ''));
@@ -143,7 +143,7 @@ public function testJson(): void
143143
{
144144
$core = $this->getCore();
145145

146-
$core->setHandler(fn() => [
146+
$core->setHandler(fn(): array => [
147147
'status' => 404,
148148
'message' => 'not found',
149149
]);
@@ -157,7 +157,7 @@ public function testJsonSerializable(): void
157157
{
158158
$core = $this->getCore();
159159

160-
$core->setHandler(fn() => new Json([
160+
$core->setHandler(fn(): Json => new Json([
161161
'status' => 404,
162162
'message' => 'not found',
163163
]));
@@ -171,7 +171,7 @@ public function testMiddleware(): void
171171
{
172172
$core = $this->getCore([HeaderMiddleware::class]);
173173

174-
$core->setHandler(fn() => 'hello?');
174+
$core->setHandler(fn(): string => 'hello?');
175175

176176
$response = $core->handle(new ServerRequest('GET', ''));
177177
$this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type'));
@@ -186,7 +186,7 @@ public function testMiddlewareTrait(): void
186186
$core->getPipeline()->pushMiddleware(new Header2Middleware());
187187
$core->getPipeline()->riseMiddleware(new HeaderMiddleware());
188188

189-
$core->setHandler(fn() => 'hello?');
189+
$core->setHandler(fn(): string => 'hello?');
190190

191191
$response = $core->handle(new ServerRequest('GET', ''));
192192
$this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type'));
@@ -201,7 +201,7 @@ public function testMiddlewareTraitReversed(): void
201201
$core->getPipeline()->pushMiddleware(new HeaderMiddleware());
202202
$core->getPipeline()->riseMiddleware(new Header2Middleware());
203203

204-
$core->setHandler(fn() => 'hello?');
204+
$core->setHandler(fn(): string => 'hello?');
205205

206206
$response = $core->handle(new ServerRequest('GET', ''));
207207
$this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type'));
@@ -237,7 +237,7 @@ public function testEventsShouldBeDispatched(): void
237237

238238
$core = $this->getCore();
239239

240-
$core->setHandler(fn() => 'hello world');
240+
$core->setHandler(fn(): string => 'hello world');
241241

242242
$response = $core->handle($request);
243243
$this->assertSame('hello world', (string)$response->getBody());
@@ -256,7 +256,7 @@ public function testPassingTracerIntoScope(): void
256256
$tracerFactory = m::mock(TracerFactoryInterface::class),
257257
);
258258

259-
$http->setHandler(fn() => 'hello world');
259+
$http->setHandler(fn(): string => 'hello world');
260260

261261
$tracerFactory
262262
->shouldReceive('make')
@@ -319,7 +319,7 @@ function ($name, $callback, $attributes, $scoped, $traceKind) {
319319
$tracerFactory,
320320
);
321321

322-
$http->setHandler(fn() => 'hello world');
322+
$http->setHandler(fn(): string => 'hello world');
323323

324324
$response = $http->handle($request);
325325
$this->assertSame('hello world', (string)$response->getBody());
@@ -338,7 +338,7 @@ public function testTraceContextIsAppliedToResponse(): void
338338
$tracerFactory = m::mock(TracerFactoryInterface::class),
339339
);
340340

341-
$http->setHandler(fn() => 'hello world');
341+
$http->setHandler(fn(): string => 'hello world');
342342

343343
$tracerFactory
344344
->shouldReceive('make')

tests/PipelineTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testTarget(): void
2828
{
2929
$pipeline = new Pipeline($this->container);
3030

31-
$handler = new CallableHandler(fn() => 'response', new ResponseFactory(new HttpConfig(['headers' => []])));
31+
$handler = new CallableHandler(fn(): string => 'response', new ResponseFactory(new HttpConfig(['headers' => []])));
3232

3333
$response = $pipeline->withHandler($handler)->handle(new ServerRequest('GET', ''));
3434

@@ -41,7 +41,7 @@ public function testHandle(): void
4141
{
4242
$pipeline = new Pipeline($this->container);
4343

44-
$handler = new CallableHandler(fn() => 'response', new ResponseFactory(new HttpConfig(['headers' => []])));
44+
$handler = new CallableHandler(fn(): string => 'response', new ResponseFactory(new HttpConfig(['headers' => []])));
4545

4646
$response = $pipeline->process(new ServerRequest('GET', ''), $handler);
4747

@@ -67,7 +67,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6767
}
6868
};
6969
$request = new ServerRequest('GET', '');
70-
$handler = new CallableHandler(fn() => 'response', new ResponseFactory(new HttpConfig(['headers' => []])));
70+
$handler = new CallableHandler(fn(): string => 'response', new ResponseFactory(new HttpConfig(['headers' => []])));
7171

7272
$dispatcher = $this->createMock(EventDispatcherInterface::class);
7373
$dispatcher
@@ -87,7 +87,7 @@ public function testRequestResetThroughPipeline(): void
8787
$this->container->getBinder('http')
8888
->bindSingleton(CurrentRequest::class, new CurrentRequest());
8989
$this->container->getBinder('http')
90-
->bind(ServerRequestInterface::class, static fn(CurrentRequest $cr) => $cr->get());
90+
->bind(ServerRequestInterface::class, static fn(CurrentRequest $cr): ?ServerRequestInterface => $cr->get());
9191

9292
$middleware = new class implements MiddlewareInterface {
9393
public function process(
@@ -109,7 +109,7 @@ public function process(
109109
new \Spiral\Core\Scope(name: 'http'),
110110
function (ScopeInterface $c) use ($middleware): void {
111111
$request = new ServerRequest('GET', '');
112-
$handler = new CallableHandler(fn() => 'response', new ResponseFactory(new HttpConfig(['headers' => []])));
112+
$handler = new CallableHandler(fn(): string => 'response', new ResponseFactory(new HttpConfig(['headers' => []])));
113113

114114
$pipeline = new Pipeline($c, null, new NullTracer($c));
115115

0 commit comments

Comments
 (0)