Skip to content

Update static CI #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/.cache/php-cs-fixer/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions .github/.cache/phpstan/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions .github/.cache/psalm/.gitignore

This file was deleted.

54 changes: 15 additions & 39 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,99 +6,75 @@ on:
jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache PHPStan
uses: actions/cache@v2
with:
path: .github/.cache/phpstan/
key: phpstan-${{ github.sha }}
restore-keys: phpstan-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
coverage: none
tools: phpstan:1.4.6, cs2pr
tools: phpstan:1.11, cs2pr

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

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

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-22.04
env:
PHP_CS_FIXER_IGNORE_ENV: 1 # required for PHP 8.2 as not yet official supported
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache PhpCsFixer
uses: actions/cache@v2
with:
path: .github/.cache/php-cs-fixer/
key: php-cs-fixer-${{ github.sha }}
restore-keys: php-cs-fixer-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
coverage: none
tools: php-cs-fixer:3.11.0, cs2pr
tools: php-cs-fixer:3.63, cs2pr

- name: Display PHP-CS-Fixer version
run: sleep 1 && php-cs-fixer --version

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

psalm:
name: Psalm
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Psalm
uses: actions/cache@v2
with:
path: .github/.cache/psalm/
key: psalm-${{ github.sha }}
restore-keys: psalm-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
coverage: none
tools: vimeo/psalm:5.17
tools: vimeo/psalm:5.25

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

- name: Psalm
run: psalm --php-version=8.2 --no-progress --output-format=github
run: psalm --no-progress --output-format=github

composer-normalize:
name: Composer Normalize
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
coverage: none
tools: composer-normalize

Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
;

return (new PhpCsFixer\Config())
->setCacheFile(__DIR__.'/.github/.cache/php-cs-fixer/.php_cs.cache')
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'fully_qualified_strict_types' => false,
])
->setFinder($finder)
;
27 changes: 17 additions & 10 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.17.0@c620f6e80d0abfca532b00bda366062aaedf6e5d">
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/bref/src/Runtime.php">
<InvalidArgument>
<code>$options</code>
<code><![CDATA[$options]]></code>
</InvalidArgument>
</file>
<file src="src/bref/src/SymfonyRequestBridge.php">
Expand All @@ -12,15 +12,12 @@
</file>
<file src="src/frankenphp-symfony/src/Runner.php">
<UndefinedVariable>
<code>$sfRequest</code>
<code><![CDATA[$sfRequest]]></code>
</UndefinedVariable>
<UndefinedFunction>
<code><![CDATA[\frankenphp_handle_request($handler)]]></code>
</UndefinedFunction>
</file>
<file src="src/frankenphp-symfony/src/Runtime.php">
<InvalidArgument>
<code>$options</code>
<code><![CDATA[$options]]></code>
</InvalidArgument>
</file>
<file src="src/google-cloud/router.php">
Expand All @@ -30,19 +27,29 @@
</file>
<file src="src/psr-17/src/Runtime.php">
<InvalidArgument>
<code>$options</code>
<code><![CDATA[$options]]></code>
</InvalidArgument>
</file>
<file src="src/psr-laminas/src/Runtime.php">
<InvalidArgument>
<code>$options</code>
<code><![CDATA[$options]]></code>
</InvalidArgument>
</file>
<file src="src/psr-nyholm-laminas/src/Runtime.php">
<InvalidArgument>
<code>$options</code>
<code><![CDATA[$options]]></code>
</InvalidArgument>
</file>
<file src="src/roadrunner-nyholm/src/Runner.php">
<UndefinedClass>
<code><![CDATA[RoadRunner\Worker]]></code>
</UndefinedClass>
</file>
<file src="src/roadrunner-symfony-nyholm/src/Runner.php">
<UndefinedClass>
<code><![CDATA[RoadRunner\Worker]]></code>
</UndefinedClass>
</file>
<file src="src/swoole/src/SymfonyHttpBridge.php">
<InvalidScalarArgument>
<code><![CDATA[$sfResponse->getStatusCode()]]></code>
Expand Down
19 changes: 7 additions & 12 deletions src/bref/src/Lambda/LambdaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private function closeReturnHandler(): void
*
* @return bool true if event was successfully handled
*
* @throws Exception
* @throws \Exception
*/
public function processNextEvent(Handler $handler): bool
{
Expand Down Expand Up @@ -167,16 +167,16 @@ private function waitNextInvocation(): array
if (curl_errno($this->handler) > 0) {
$message = curl_error($this->handler);
$this->closeHandler();
throw new Exception('Failed to fetch next Lambda invocation: '.$message);
throw new \Exception('Failed to fetch next Lambda invocation: '.$message);
}
if ('' === $body) {
throw new Exception('Empty Lambda runtime API response');
throw new \Exception('Empty Lambda runtime API response');
}

$context = $contextBuilder->buildContext();

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

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

/**
* @param mixed $responseData
*
* @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html#runtimes-api-response
*/
private function sendResponse(string $invocationId, $responseData): void
Expand Down Expand Up @@ -246,7 +244,7 @@ public function failInitialization(string $message, ?\Throwable $error = null):
// Log the exception in CloudWatch
echo "$message\n";
if ($error) {
if ($error instanceof Exception) {
if ($error instanceof \Exception) {
$errorMessage = get_class($error).': '.$error->getMessage();
} else {
$errorMessage = $error->getMessage();
Expand All @@ -270,14 +268,11 @@ public function failInitialization(string $message, ?\Throwable $error = null):
exit(1);
}

/**
* @param mixed $data
*/
private function postJson(string $url, $data): void
{
$jsonData = json_encode($data);
if (false === $jsonData) {
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()));
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()));
}

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

Expand Down
2 changes: 0 additions & 2 deletions src/bref/src/SymfonyRequestBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ private static function parseBodyAndUploadedFiles(HttpRequestEvent $event): arra

/**
* Parse a string key like "files[id_cards][jpg][]" and do $array['files']['id_cards']['jpg'][] = $value.
*
* @param mixed $value
*/
private static function parseKeyAndInsertValueInArray(array &$array, string $key, $value): void
{
Expand Down
31 changes: 10 additions & 21 deletions src/bref/tests/Lambda/LambdaClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function test basic behavior()
{
$this->givenAnEvent(['Hello' => 'world!']);

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

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

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

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

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

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

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

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

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

public function test generic event handler()
{
$handler = new class() implements Handler {
/**
* @param mixed $event
*
* @return mixed
*/
$handler = new class implements Handler {
public function handle($event, Context $context)
{
return $event;
Expand All @@ -235,9 +230,6 @@ public function handle($event, Context $context)
$this->assertInvocationResult(['foo' => 'bar']);
}

/**
* @param mixed $event
*/
private function givenAnEvent($event): void
{
Server::enqueue([
Expand All @@ -253,9 +245,6 @@ private function givenAnEvent($event): void
]);
}

/**
* @param mixed $result
*/
private function assertInvocationResult($result)
{
$requests = Server::received();
Expand Down
Loading
Loading