Skip to content

Commit f0176f1

Browse files
authored
Update static CI (#180)
1 parent e738c3a commit f0176f1

File tree

4 files changed

+20
-38
lines changed

4 files changed

+20
-38
lines changed

src/Lambda/LambdaClient.php

+7-12
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private function closeReturnHandler(): void
9393
*
9494
* @return bool true if event was successfully handled
9595
*
96-
* @throws Exception
96+
* @throws \Exception
9797
*/
9898
public function processNextEvent(Handler $handler): bool
9999
{
@@ -167,16 +167,16 @@ private function waitNextInvocation(): array
167167
if (curl_errno($this->handler) > 0) {
168168
$message = curl_error($this->handler);
169169
$this->closeHandler();
170-
throw new Exception('Failed to fetch next Lambda invocation: '.$message);
170+
throw new \Exception('Failed to fetch next Lambda invocation: '.$message);
171171
}
172172
if ('' === $body) {
173-
throw new Exception('Empty Lambda runtime API response');
173+
throw new \Exception('Empty Lambda runtime API response');
174174
}
175175

176176
$context = $contextBuilder->buildContext();
177177

178178
if ('' === $context->getAwsRequestId()) {
179-
throw new Exception('Failed to determine the Lambda invocation ID');
179+
throw new \Exception('Failed to determine the Lambda invocation ID');
180180
}
181181

182182
$event = json_decode($body, true);
@@ -185,8 +185,6 @@ private function waitNextInvocation(): array
185185
}
186186

187187
/**
188-
* @param mixed $responseData
189-
*
190188
* @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html#runtimes-api-response
191189
*/
192190
private function sendResponse(string $invocationId, $responseData): void
@@ -246,7 +244,7 @@ public function failInitialization(string $message, ?\Throwable $error = null):
246244
// Log the exception in CloudWatch
247245
echo "$message\n";
248246
if ($error) {
249-
if ($error instanceof Exception) {
247+
if ($error instanceof \Exception) {
250248
$errorMessage = get_class($error).': '.$error->getMessage();
251249
} else {
252250
$errorMessage = $error->getMessage();
@@ -270,14 +268,11 @@ public function failInitialization(string $message, ?\Throwable $error = null):
270268
exit(1);
271269
}
272270

273-
/**
274-
* @param mixed $data
275-
*/
276271
private function postJson(string $url, $data): void
277272
{
278273
$jsonData = json_encode($data);
279274
if (false === $jsonData) {
280-
throw new Exception(sprintf("The Lambda response cannot be encoded to JSON.\nThis error usually happens when you try to return binary content. If you are writing an HTTP application and you want to return a binary HTTP response (like an image, a PDF, etc.), please read this guide: https://bref.sh/docs/runtimes/http.html#binary-responses\nHere is the original JSON error: '%s'", json_last_error_msg()));
275+
throw new \Exception(sprintf("The Lambda response cannot be encoded to JSON.\nThis error usually happens when you try to return binary content. If you are writing an HTTP application and you want to return a binary HTTP response (like an image, a PDF, etc.), please read this guide: https://bref.sh/docs/runtimes/http.html#binary-responses\nHere is the original JSON error: '%s'", json_last_error_msg()));
281276
}
282277

283278
if (null === $this->returnHandler) {
@@ -297,7 +292,7 @@ private function postJson(string $url, $data): void
297292
if (curl_errno($this->returnHandler) > 0) {
298293
$errorMessage = curl_error($this->returnHandler);
299294
$this->closeReturnHandler();
300-
throw new Exception('Error while calling the Lambda runtime API: '.$errorMessage);
295+
throw new \Exception('Error while calling the Lambda runtime API: '.$errorMessage);
301296
}
302297
}
303298

src/SymfonyRequestBridge.php

-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ private static function parseBodyAndUploadedFiles(HttpRequestEvent $event): arra
106106

107107
/**
108108
* Parse a string key like "files[id_cards][jpg][]" and do $array['files']['id_cards']['jpg'][] = $value.
109-
*
110-
* @param mixed $value
111109
*/
112110
private static function parseKeyAndInsertValueInArray(array &$array, string $key, $value): void
113111
{

tests/Lambda/LambdaClientTest.php

+10-21
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function test basic behavior()
3636
{
3737
$this->givenAnEvent(['Hello' => 'world!']);
3838

39-
$output = $this->lambda->processNextEvent(new class() implements Handler {
39+
$output = $this->lambda->processNextEvent(new class implements Handler {
4040
public function handle($event, Context $context)
4141
{
4242
return ['hello' => 'world'];
@@ -51,7 +51,7 @@ public function test handler receives context()
5151
{
5252
$this->givenAnEvent(['Hello' => 'world!']);
5353

54-
$this->lambda->processNextEvent(new class() implements Handler {
54+
$this->lambda->processNextEvent(new class implements Handler {
5555
public function handle($event, Context $context)
5656
{
5757
return ['hello' => 'world', 'received-function-arn' => $context->getInvokedFunctionArn()];
@@ -68,7 +68,7 @@ public function test exceptions in the handler result in an invocation 
6868
{
6969
$this->givenAnEvent(['Hello' => 'world!']);
7070

71-
$output = $this->lambda->processNextEvent(new class() implements Handler {
71+
$output = $this->lambda->processNextEvent(new class implements Handler {
7272
public function handle($event, Context $context)
7373
{
7474
throw new \RuntimeException('This is an exception');
@@ -84,7 +84,7 @@ public function test nested exceptions in the handler result in an invo
8484
{
8585
$this->givenAnEvent(['Hello' => 'world!']);
8686

87-
$this->lambda->processNextEvent(new class() implements Handler {
87+
$this->lambda->processNextEvent(new class implements Handler {
8888
public function handle($event, Context $context)
8989
{
9090
throw new \RuntimeException('This is an exception', 0, new \RuntimeException('The previous exception.', 0, new \Exception('The original exception.')));
@@ -112,7 +112,7 @@ public function test an error is thrown if the runtime API returns a 
112112
),
113113
]);
114114

115-
$this->lambda->processNextEvent(new class() implements Handler {
115+
$this->lambda->processNextEvent(new class implements Handler {
116116
public function handle($event, Context $context)
117117
{
118118
}
@@ -130,7 +130,7 @@ public function test an error is thrown if the invocation id is missin
130130
),
131131
]);
132132

133-
$this->lambda->processNextEvent(new class() implements Handler {
133+
$this->lambda->processNextEvent(new class implements Handler {
134134
public function handle($event, Context $context)
135135
{
136136
}
@@ -149,7 +149,7 @@ public function test an error is thrown if the invocation body is empt
149149
),
150150
]);
151151

152-
$this->lambda->processNextEvent(new class() implements Handler {
152+
$this->lambda->processNextEvent(new class implements Handler {
153153
public function handle($event, Context $context)
154154
{
155155
}
@@ -170,7 +170,7 @@ public function test a wrong response from the runtime API turns the i
170170
new Response(200),
171171
]);
172172

173-
$this->lambda->processNextEvent(new class() implements Handler {
173+
$this->lambda->processNextEvent(new class implements Handler {
174174
public function handle($event, Context $context)
175175
{
176176
return $event;
@@ -198,7 +198,7 @@ public function test function results that cannot be encoded are reporte
198198
{
199199
$this->givenAnEvent(['hello' => 'world!']);
200200

201-
$this->lambda->processNextEvent(new class() implements Handler {
201+
$this->lambda->processNextEvent(new class implements Handler {
202202
public function handle($event, Context $context)
203203
{
204204
return "\xB1\x31";
@@ -216,12 +216,7 @@ public function handle($event, Context $context)
216216

217217
public function test generic event handler()
218218
{
219-
$handler = new class() implements Handler {
220-
/**
221-
* @param mixed $event
222-
*
223-
* @return mixed
224-
*/
219+
$handler = new class implements Handler {
225220
public function handle($event, Context $context)
226221
{
227222
return $event;
@@ -235,9 +230,6 @@ public function handle($event, Context $context)
235230
$this->assertInvocationResult(['foo' => 'bar']);
236231
}
237232

238-
/**
239-
* @param mixed $event
240-
*/
241233
private function givenAnEvent($event): void
242234
{
243235
Server::enqueue([
@@ -253,9 +245,6 @@ private function givenAnEvent($event): void
253245
]);
254246
}
255247

256-
/**
257-
* @param mixed $result
258-
*/
259248
private function assertInvocationResult($result)
260249
{
261250
$requests = Server::received();

tests/SymfonyRequestBridgeTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testRawContent()
6262
------------------------------83ff53821b7c--
6363
6464
HTTP
65-
,
65+
,
6666
]), $this->getContext());
6767
$this->assertSame('', $request->getContent());
6868
}
@@ -91,7 +91,7 @@ public function testUploadedFile()
9191
------------------------------83ff53821b7c--
9292
9393
HTTP
94-
,
94+
,
9595
]), $this->getContext());
9696
$files = $request->files->all();
9797
$this->assertArrayHasKey('img', $files['form']);
@@ -125,7 +125,7 @@ public function testEmptyUploadedFile()
125125
------------------------------83ff53821b7c--
126126
127127
HTTP
128-
,
128+
,
129129
]), $this->getContext());
130130
$files = $request->files->all();
131131
$this->assertArrayHasKey('img', $files['form']);

0 commit comments

Comments
 (0)