Skip to content

Commit 871db84

Browse files
add return method value types
1 parent 8f0a23c commit 871db84

21 files changed

+54
-53
lines changed

Diff for: src/bref/src/ConsoleApplicationHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(Application $application)
2323
$this->application->setAutoExit(false);
2424
}
2525

26-
public function handle($event, Context $context)
26+
public function handle($event, Context $context): array
2727
{
2828
$args = \Clue\Arguments\split((string) $event);
2929
array_unshift($args, 'command');

Diff for: src/bref/src/Runtime.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getRunner(?object $application): RunnerInterface
4646
}
4747
}
4848

49-
private function tryToFindRunner(?object $application)
49+
private function tryToFindRunner(?object $application): RunnerInterface
5050
{
5151
if ($application instanceof ContainerInterface) {
5252
$handler = explode(':', $_SERVER['_HANDLER']);

Diff for: src/bref/tests/Lambda/LambdaClientTest.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ protected function tearDown(): void
3232
ob_end_clean();
3333
}
3434

35-
public function test basic behavior()
35+
public function test basic behavior(): void
3636
{
3737
$this->givenAnEvent(['Hello' => 'world!']);
3838

3939
$output = $this->lambda->processNextEvent(new class implements Handler {
40-
public function handle($event, Context $context)
40+
public function handle($event, Context $context): array
4141
{
4242
return ['hello' => 'world'];
4343
}
@@ -47,12 +47,12 @@ public function handle($event, Context $context)
4747
$this->assertInvocationResult(['hello' => 'world']);
4848
}
4949

50-
public function test handler receives context()
50+
public function test handler receives context(): void
5151
{
5252
$this->givenAnEvent(['Hello' => 'world!']);
5353

5454
$this->lambda->processNextEvent(new class implements Handler {
55-
public function handle($event, Context $context)
55+
public function handle($event, Context $context): array
5656
{
5757
return ['hello' => 'world', 'received-function-arn' => $context->getInvokedFunctionArn()];
5858
}
@@ -64,7 +64,7 @@ public function handle($event, Context $context)
6464
]);
6565
}
6666

67-
public function test exceptions in the handler result in an invocation error()
67+
public function test exceptions in the handler result in an invocation error(): void
6868
{
6969
$this->givenAnEvent(['Hello' => 'world!']);
7070

@@ -80,7 +80,7 @@ public function handle($event, Context $context)
8080
$this->assertErrorInLogs('RuntimeException', 'This is an exception');
8181
}
8282

83-
public function test nested exceptions in the handler result in an invocation error()
83+
public function test nested exceptions in the handler result in an invocation error(): void
8484
{
8585
$this->givenAnEvent(['Hello' => 'world!']);
8686

@@ -99,7 +99,7 @@ public function handle($event, Context $context)
9999
]);
100100
}
101101

102-
public function test an error is thrown if the runtime API returns a wrong response()
102+
public function test an error is thrown if the runtime API returns a wrong response(): void
103103
{
104104
$this->expectExceptionMessage('Failed to fetch next Lambda invocation: The requested URL returned error: 404');
105105
Server::enqueue([
@@ -119,7 +119,7 @@ public function handle($event, Context $context)
119119
});
120120
}
121121

122-
public function test an error is thrown if the invocation id is missing()
122+
public function test an error is thrown if the invocation id is missing(): void
123123
{
124124
$this->expectExceptionMessage('Failed to determine the Lambda invocation ID');
125125
Server::enqueue([
@@ -137,7 +137,7 @@ public function handle($event, Context $context)
137137
});
138138
}
139139

140-
public function test an error is thrown if the invocation body is empty()
140+
public function test an error is thrown if the invocation body is empty(): void
141141
{
142142
$this->expectExceptionMessage('Empty Lambda runtime API response');
143143
Server::enqueue([
@@ -156,7 +156,7 @@ public function handle($event, Context $context)
156156
});
157157
}
158158

159-
public function test a wrong response from the runtime API turns the invocation into an error()
159+
public function test a wrong response from the runtime API turns the invocation into an error(): void
160160
{
161161
Server::enqueue([
162162
new Response( // lambda event
@@ -194,12 +194,12 @@ public function handle($event, Context $context)
194194
$this->assertErrorInLogs('Exception', 'Error while calling the Lambda runtime API: The requested URL returned error: 400');
195195
}
196196

197-
public function test function results that cannot be encoded are reported as invocation errors()
197+
public function test function results that cannot be encoded are reported as invocation errors(): void
198198
{
199199
$this->givenAnEvent(['hello' => 'world!']);
200200

201201
$this->lambda->processNextEvent(new class implements Handler {
202-
public function handle($event, Context $context)
202+
public function handle($event, Context $context): string
203203
{
204204
return "\xB1\x31";
205205
}
@@ -214,7 +214,7 @@ public function handle($event, Context $context)
214214
$this->assertErrorInLogs('Exception', $message);
215215
}
216216

217-
public function test generic event handler()
217+
public function test generic event handler(): void
218218
{
219219
$handler = new class implements Handler {
220220
public function handle($event, Context $context)
@@ -245,7 +245,7 @@ private function givenAnEvent($event): void
245245
]);
246246
}
247247

248-
private function assertInvocationResult($result)
248+
private function assertInvocationResult($result): void
249249
{
250250
$requests = Server::received();
251251
$this->assertCount(2, $requests);
@@ -258,7 +258,7 @@ private function assertInvocationResult($result)
258258
$this->assertEquals($result, json_decode($eventResponse->getBody()->__toString(), true));
259259
}
260260

261-
private function assertInvocationErrorResult(string $errorClass, string $errorMessage)
261+
private function assertInvocationErrorResult(string $errorClass, string $errorMessage): void
262262
{
263263
$requests = Server::received();
264264
$this->assertCount(2, $requests);
@@ -305,7 +305,7 @@ private function assertErrorInLogs(string $errorClass, string $errorMessage): vo
305305
$this->assertIsArray($invocationResult['stack']);
306306
}
307307

308-
private function assertPreviousErrorsInLogs(array $previousErrors)
308+
private function assertPreviousErrorsInLogs(array $previousErrors): void
309309
{
310310
// Decode the logs from stdout
311311
$stdout = $this->getActualOutput();

Diff for: src/bref/tests/SymfonyRequestBridgeTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class SymfonyRequestBridgeTest extends TestCase
1313
{
14-
public function testClientIpFromForwardedFor()
14+
public function testClientIpFromForwardedFor(): void
1515
{
1616
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
1717
'requestContext' => ['http' => ['method' => 'GET']],
@@ -23,7 +23,7 @@ public function testClientIpFromForwardedFor()
2323
/**
2424
* Raw content should only exist when there is no multipart content.
2525
*/
26-
public function testRawContent()
26+
public function testRawContent(): void
2727
{
2828
// No content type
2929
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
@@ -67,7 +67,7 @@ public function testRawContent()
6767
$this->assertSame('', $request->getContent());
6868
}
6969

70-
public function testUploadedFile()
70+
public function testUploadedFile(): void
7171
{
7272
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
7373
'requestContext' => ['http' => ['method' => 'POST']],
@@ -107,7 +107,7 @@ public function testUploadedFile()
107107
$this->assertSame('bar', $post['foo']);
108108
}
109109

110-
public function testEmptyUploadedFile()
110+
public function testEmptyUploadedFile(): void
111111
{
112112
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
113113
'requestContext' => ['http' => ['method' => 'POST']],
@@ -136,7 +136,7 @@ public function testEmptyUploadedFile()
136136
$this->assertSame('bar', $post['foo']);
137137
}
138138

139-
public function testLambdaContext()
139+
public function testLambdaContext(): void
140140
{
141141
$requestContext = ['http' => ['method' => 'GET']];
142142
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
@@ -149,7 +149,7 @@ public function testLambdaContext()
149149
$this->assertSame(json_encode($requestContext), $request->server->get('LAMBDA_REQUEST_CONTEXT'));
150150
}
151151

152-
private function getContext()
152+
private function getContext(): Context
153153
{
154154
// this is set in LaravelHttpHandler and SymfonyHttpHandler to allow overwrite of this value
155155
Request::setTrustedProxies(['127.0.0.1'], Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO);

Diff for: src/google-cloud/google/CloudEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getData()
8181
return $this->data;
8282
}
8383

84-
public static function fromArray(array $arr)
84+
public static function fromArray(array $arr): static
8585
{
8686
$args = [];
8787
$argKeys = [

Diff for: src/google-cloud/google/Context.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function getResourceName(): ?string
5454
return $this->resource['name'] ?? null;
5555
}
5656

57-
public static function fromArray(array $arr)
57+
public static function fromArray(array $arr): static
5858
{
5959
// When "resource" is defined in the root (instead of in "context") it
6060
// is a string representing the resource name

Diff for: src/google-cloud/src/Runtime.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected function createCloudEvent(): ?CloudEvent
9090
}
9191
}
9292

93-
protected function sendHttpResponseAndExit(int $status, string $body, array $headers)
93+
protected function sendHttpResponseAndExit(int $status, string $body, array $headers): void
9494
{
9595
error_log($body);
9696
header('HTTP/1.1 '.$status);

Diff for: src/google-cloud/tests/google/CloudEventTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
class CloudEventTest extends TestCase
2828
{
29-
public function testJsonSerialize()
29+
public function testJsonSerialize(): void
3030
{
3131
$event = new CloudEvent(
3232
'1413058901901494',

Diff for: src/google-cloud/tests/google/ContextTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
class ContextTest extends TestCase
2828
{
29-
public function testFromArray()
29+
public function testFromArray(): void
3030
{
3131
$context = Context::fromArray([
3232
'eventId' => 'abc',
@@ -45,7 +45,7 @@ public function testFromArray()
4545
$this->assertEquals('mno', $context->getService());
4646
}
4747

48-
public function testFromEmptyArray()
48+
public function testFromEmptyArray(): void
4949
{
5050
$context = Context::fromArray([]);
5151
$this->assertEquals(null, $context->getEventId());

Diff for: src/google-cloud/tests/google/LegacyEventMapperTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
class LegacyEventMapperTest extends TestCase
2828
{
29-
public function testWithContextProperty()
29+
public function testWithContextProperty(): void
3030
{
3131
$mapper = new LegacyEventMapper();
3232
$jsonData = [
@@ -61,7 +61,7 @@ public function testWithContextProperty()
6161
$this->assertEquals(['message' => 'foo'], $cloudevent->getData());
6262
}
6363

64-
public function testWithoutContextProperty()
64+
public function testWithoutContextProperty(): void
6565
{
6666
$mapper = new LegacyEventMapper();
6767
$jsonData = [
@@ -95,7 +95,7 @@ public function testWithoutContextProperty()
9595
$this->assertEquals(['message' => 'foo'], $cloudevent->getData());
9696
}
9797

98-
public function testResourceAsString()
98+
public function testResourceAsString(): void
9999
{
100100
$mapper = new LegacyEventMapper();
101101
$jsonData = [
@@ -126,7 +126,7 @@ public function testResourceAsString()
126126
$this->assertEquals(['message' => 'foo'], $cloudevent->getData());
127127
}
128128

129-
public function testCloudStorage()
129+
public function testCloudStorage(): void
130130
{
131131
$mapper = new LegacyEventMapper();
132132
$jsonData = [
@@ -163,7 +163,7 @@ public function testCloudStorage()
163163
$this->assertEquals('foo', $cloudevent->getData());
164164
}
165165

166-
public function testFirebaseAuth()
166+
public function testFirebaseAuth(): void
167167
{
168168
$mapper = new LegacyEventMapper();
169169
$jsonData = [

Diff for: src/google-cloud/tests/runtime/AutoDiscoverTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class AutoDiscoverTest extends TestCase
99
{
10-
public function testAutoDiscoverClasses()
10+
public function testAutoDiscoverClasses(): void
1111
{
1212
$classes = [
1313
'Symfony\Runtime\Google\CloudFunctions\CloudEventRuntime',

Diff for: src/google-cloud/tests/runtime/RuntimeTest.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace Runtime\GoogleCloud\Tests;
44

55
use Google\CloudFunctions\CloudEvent;
6+
use PHPUnit\Framework\MockObject\MockObject;
67
use PHPUnit\Framework\TestCase;
78
use Runtime\GoogleCloud\Runtime;
89
use Symfony\Component\Runtime\RuntimeInterface;
910

1011
class RuntimeTest extends TestCase
1112
{
12-
public function testStructuredType()
13+
public function testStructuredType(): void
1314
{
1415
$input = [
1516
'id' => '1234567890',
@@ -28,7 +29,7 @@ public function testStructuredType()
2829
$this->assertSame('com.google.cloud.pubsub.topic.publish', $output->getType());
2930
}
3031

31-
public function testLegacyType()
32+
public function testLegacyType(): void
3233
{
3334
$input = [
3435
'data' => 'foo',
@@ -54,7 +55,7 @@ public function testLegacyType()
5455
$this->assertSame('google.cloud.pubsub.topic.v1.messagePublished', $output->getType());
5556
}
5657

57-
public function testValidateJsonWithJsonContentType()
58+
public function testValidateJsonWithJsonContentType(): void
5859
{
5960
$runtime = $this->getRuntimeMock();
6061
$runtime->method('getBody')->willReturn('not json');
@@ -64,7 +65,7 @@ public function testValidateJsonWithJsonContentType()
6465
$this->invokeCreateCloudEvent($runtime);
6566
}
6667

67-
public function testValidateJsonWithStructuredType()
68+
public function testValidateJsonWithStructuredType(): void
6869
{
6970
$runtime = $this->getRuntimeMock();
7071
$runtime->method('getBody')->willReturn('not json');
@@ -74,7 +75,7 @@ public function testValidateJsonWithStructuredType()
7475
$this->invokeCreateCloudEvent($runtime);
7576
}
7677

77-
public function testValidateJsonWithLegacyType()
78+
public function testValidateJsonWithLegacyType(): void
7879
{
7980
$runtime = $this->getRuntimeMock();
8081
$runtime->method('getBody')->willReturn('not json');
@@ -84,7 +85,7 @@ public function testValidateJsonWithLegacyType()
8485
$this->invokeCreateCloudEvent($runtime);
8586
}
8687

87-
public function testNoValidateJsonWithBinaryType()
88+
public function testNoValidateJsonWithBinaryType(): void
8889
{
8990
$runtime = $this->getRuntimeMock();
9091
$runtime->method('getBody')->willReturn('not json');
@@ -110,9 +111,9 @@ private function invokeCreateCloudEvent(RuntimeInterface $runtime): ?CloudEvent
110111
}
111112

112113
/**
113-
* @return \PHPUnit\Framework\MockObject\MockObject|Runtime
114+
* @return MockObject&Runtime
114115
*/
115-
private function getRuntimeMock()
116+
private function getRuntimeMock(): mixed
116117
{
117118
$runtime = $this->getMockBuilder(Runtime::class)
118119
->disableOriginalConstructor()

Diff for: src/psr-17/src/Runtime.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected static function register(GenericRuntime $runtime): GenericRuntime
7474
/**
7575
* @return ServerRequestInterface
7676
*/
77-
private function createRequest()
77+
private function createRequest(): ServerRequestInterface
7878
{
7979
if (null === $this->requestCreator) {
8080
$creatorClass = $this->options['server_request_creator'] ?? ServerRequestCreator::class;

0 commit comments

Comments
 (0)