Skip to content

Commit 6d61e07

Browse files
authored
Update static CI (#180)
1 parent 237c849 commit 6d61e07

File tree

21 files changed

+82
-128
lines changed

21 files changed

+82
-128
lines changed

.github/.cache/php-cs-fixer/.gitignore

-2
This file was deleted.

.github/.cache/phpstan/.gitignore

-2
This file was deleted.

.github/.cache/psalm/.gitignore

-2
This file was deleted.

.github/workflows/static.yml

+15-39
Original file line numberDiff line numberDiff line change
@@ -6,99 +6,75 @@ on:
66
jobs:
77
phpstan:
88
name: PHPStan
9-
runs-on: ubuntu-22.04
9+
runs-on: ubuntu-latest
1010

1111
steps:
1212
- name: Checkout code
1313
uses: actions/checkout@v4
1414

15-
- name: Cache PHPStan
16-
uses: actions/cache@v2
17-
with:
18-
path: .github/.cache/phpstan/
19-
key: phpstan-${{ github.sha }}
20-
restore-keys: phpstan-
21-
2215
- name: Setup PHP
2316
uses: shivammathur/setup-php@v2
2417
with:
25-
php-version: 8.2
18+
php-version: 8.3
2619
coverage: none
27-
tools: phpstan:1.4.6, cs2pr
20+
tools: phpstan:1.11, cs2pr
2821

2922
- name: Download dependencies
3023
uses: ramsey/composer-install@v2
31-
with:
32-
composer-options: "--ignore-platform-reqs" # required for PHP 8.2 as not yet official supported
3324

3425
- name: PHPStan
3526
run: phpstan analyze --no-progress --error-format=checkstyle | cs2pr
3627

3728
php-cs-fixer:
3829
name: PHP-CS-Fixer
39-
runs-on: ubuntu-22.04
40-
env:
41-
PHP_CS_FIXER_IGNORE_ENV: 1 # required for PHP 8.2 as not yet official supported
30+
runs-on: ubuntu-latest
4231

4332
steps:
4433
- name: Checkout code
4534
uses: actions/checkout@v4
4635

47-
- name: Cache PhpCsFixer
48-
uses: actions/cache@v2
49-
with:
50-
path: .github/.cache/php-cs-fixer/
51-
key: php-cs-fixer-${{ github.sha }}
52-
restore-keys: php-cs-fixer-
53-
5436
- name: Setup PHP
5537
uses: shivammathur/setup-php@v2
5638
with:
57-
php-version: 8.2
39+
php-version: 8.3
5840
coverage: none
59-
tools: php-cs-fixer:3.11.0, cs2pr
41+
tools: php-cs-fixer:3.63, cs2pr
42+
43+
- name: Display PHP-CS-Fixer version
44+
run: sleep 1 && php-cs-fixer --version
6045

6146
- name: PHP-CS-Fixer
6247
run: php-cs-fixer fix --dry-run --format=checkstyle | cs2pr
6348

6449
psalm:
6550
name: Psalm
66-
runs-on: ubuntu-22.04
51+
runs-on: ubuntu-latest
6752
steps:
6853
- name: Checkout code
6954
uses: actions/checkout@v4
7055

71-
- name: Cache Psalm
72-
uses: actions/cache@v2
73-
with:
74-
path: .github/.cache/psalm/
75-
key: psalm-${{ github.sha }}
76-
restore-keys: psalm-
77-
7856
- name: Setup PHP
7957
uses: shivammathur/setup-php@v2
8058
with:
81-
php-version: 8.2
59+
php-version: 8.3
8260
coverage: none
83-
tools: vimeo/psalm:5.17
61+
tools: vimeo/psalm:5.25
8462

8563
- name: Download dependencies
8664
uses: ramsey/composer-install@v2
87-
with:
88-
composer-options: "--ignore-platform-reqs" # required for PHP 8.2 as not yet official supported
8965

9066
- name: Psalm
91-
run: psalm --php-version=8.2 --no-progress --output-format=github
67+
run: psalm --no-progress --output-format=github
9268

9369
composer-normalize:
9470
name: Composer Normalize
95-
runs-on: ubuntu-22.04
71+
runs-on: ubuntu-latest
9672

9773
steps:
9874
- name: Setup PHP
9975
uses: shivammathur/setup-php@v2
10076
with:
101-
php-version: 8.2
77+
php-version: 8.3
10278
coverage: none
10379
tools: composer-normalize
10480

.php-cs-fixer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
;
66

77
return (new PhpCsFixer\Config())
8-
->setCacheFile(__DIR__.'/.github/.cache/php-cs-fixer/.php_cs.cache')
98
->setRiskyAllowed(true)
109
->setRules([
1110
'@PSR2' => true,
1211
'@Symfony' => true,
12+
'fully_qualified_strict_types' => false,
1313
])
1414
->setFinder($finder)
1515
;

psalm.baseline.xml

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.17.0@c620f6e80d0abfca532b00bda366062aaedf6e5d">
2+
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
33
<file src="src/bref/src/Runtime.php">
44
<InvalidArgument>
5-
<code>$options</code>
5+
<code><![CDATA[$options]]></code>
66
</InvalidArgument>
77
</file>
88
<file src="src/bref/src/SymfonyRequestBridge.php">
@@ -12,15 +12,12 @@
1212
</file>
1313
<file src="src/frankenphp-symfony/src/Runner.php">
1414
<UndefinedVariable>
15-
<code>$sfRequest</code>
15+
<code><![CDATA[$sfRequest]]></code>
1616
</UndefinedVariable>
17-
<UndefinedFunction>
18-
<code><![CDATA[\frankenphp_handle_request($handler)]]></code>
19-
</UndefinedFunction>
2017
</file>
2118
<file src="src/frankenphp-symfony/src/Runtime.php">
2219
<InvalidArgument>
23-
<code>$options</code>
20+
<code><![CDATA[$options]]></code>
2421
</InvalidArgument>
2522
</file>
2623
<file src="src/google-cloud/router.php">
@@ -30,19 +27,29 @@
3027
</file>
3128
<file src="src/psr-17/src/Runtime.php">
3229
<InvalidArgument>
33-
<code>$options</code>
30+
<code><![CDATA[$options]]></code>
3431
</InvalidArgument>
3532
</file>
3633
<file src="src/psr-laminas/src/Runtime.php">
3734
<InvalidArgument>
38-
<code>$options</code>
35+
<code><![CDATA[$options]]></code>
3936
</InvalidArgument>
4037
</file>
4138
<file src="src/psr-nyholm-laminas/src/Runtime.php">
4239
<InvalidArgument>
43-
<code>$options</code>
40+
<code><![CDATA[$options]]></code>
4441
</InvalidArgument>
4542
</file>
43+
<file src="src/roadrunner-nyholm/src/Runner.php">
44+
<UndefinedClass>
45+
<code><![CDATA[RoadRunner\Worker]]></code>
46+
</UndefinedClass>
47+
</file>
48+
<file src="src/roadrunner-symfony-nyholm/src/Runner.php">
49+
<UndefinedClass>
50+
<code><![CDATA[RoadRunner\Worker]]></code>
51+
</UndefinedClass>
52+
</file>
4653
<file src="src/swoole/src/SymfonyHttpBridge.php">
4754
<InvalidScalarArgument>
4855
<code><![CDATA[$sfResponse->getStatusCode()]]></code>

src/bref/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/bref/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
{

src/bref/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();

0 commit comments

Comments
 (0)