diff --git a/.github/.cache/php-cs-fixer/.gitignore b/.github/.cache/php-cs-fixer/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/.github/.cache/php-cs-fixer/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/.github/.cache/phpstan/.gitignore b/.github/.cache/phpstan/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/.github/.cache/phpstan/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/.github/.cache/psalm/.gitignore b/.github/.cache/psalm/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/.github/.cache/psalm/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index d43f5ae..c846619 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -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 diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 33e71d2..7d86bde 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -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) ; diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 0e8b3df..cc89e29 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -1,8 +1,8 @@ - + - $options + @@ -12,15 +12,12 @@ - $sfRequest + - - - - $options + @@ -30,19 +27,29 @@ - $options + - $options + - $options + + + + + + + + + + + getStatusCode()]]> diff --git a/src/bref/src/Lambda/LambdaClient.php b/src/bref/src/Lambda/LambdaClient.php index 1e851f9..e973a7c 100755 --- a/src/bref/src/Lambda/LambdaClient.php +++ b/src/bref/src/Lambda/LambdaClient.php @@ -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 { @@ -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); @@ -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 @@ -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(); @@ -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) { @@ -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); } } diff --git a/src/bref/src/SymfonyRequestBridge.php b/src/bref/src/SymfonyRequestBridge.php index 9a5e076..094e5c5 100644 --- a/src/bref/src/SymfonyRequestBridge.php +++ b/src/bref/src/SymfonyRequestBridge.php @@ -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 { diff --git a/src/bref/tests/Lambda/LambdaClientTest.php b/src/bref/tests/Lambda/LambdaClientTest.php index 6f6a24f..37d80cd 100644 --- a/src/bref/tests/Lambda/LambdaClientTest.php +++ b/src/bref/tests/Lambda/LambdaClientTest.php @@ -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']; @@ -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()]; @@ -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'); @@ -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.'))); @@ -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) { } @@ -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) { } @@ -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) { } @@ -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; @@ -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"; @@ -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; @@ -235,9 +230,6 @@ public function handle($event, Context $context) $this->assertInvocationResult(['foo' => 'bar']); } - /** - * @param mixed $event - */ private function givenAnEvent($event): void { Server::enqueue([ @@ -253,9 +245,6 @@ private function givenAnEvent($event): void ]); } - /** - * @param mixed $result - */ private function assertInvocationResult($result) { $requests = Server::received(); diff --git a/src/bref/tests/SymfonyRequestBridgeTest.php b/src/bref/tests/SymfonyRequestBridgeTest.php index 0dc5248..4943724 100644 --- a/src/bref/tests/SymfonyRequestBridgeTest.php +++ b/src/bref/tests/SymfonyRequestBridgeTest.php @@ -62,7 +62,7 @@ public function testRawContent() ------------------------------83ff53821b7c-- HTTP -, + , ]), $this->getContext()); $this->assertSame('', $request->getContent()); } @@ -91,7 +91,7 @@ public function testUploadedFile() ------------------------------83ff53821b7c-- HTTP -, + , ]), $this->getContext()); $files = $request->files->all(); $this->assertArrayHasKey('img', $files['form']); @@ -125,7 +125,7 @@ public function testEmptyUploadedFile() ------------------------------83ff53821b7c-- HTTP -, + , ]), $this->getContext()); $files = $request->files->all(); $this->assertArrayHasKey('img', $files['form']); diff --git a/src/google-cloud/google/CloudEvent.php b/src/google-cloud/google/CloudEvent.php index bcaf396..e2820c7 100644 --- a/src/google-cloud/google/CloudEvent.php +++ b/src/google-cloud/google/CloudEvent.php @@ -18,9 +18,7 @@ namespace Google\CloudFunctions; -use JsonSerializable; - -class CloudEvent implements JsonSerializable +class CloudEvent implements \JsonSerializable { // Required Fields private $id; @@ -33,9 +31,6 @@ class CloudEvent implements JsonSerializable private $dataschema; private $subject; private $time; - /** - * @var mixed - */ private $data; final public function __construct( @@ -47,7 +42,7 @@ final public function __construct( ?string $dataschema, ?string $subject, ?string $time, - $data + $data, ) { $this->id = $id; $this->source = $source; @@ -100,9 +95,6 @@ public function getTime(): ?string return $this->time; } - /** - * @return mixed - */ public function getData() { return $this->data; diff --git a/src/google-cloud/google/Context.php b/src/google-cloud/google/Context.php index fcd13b7..a462fbc 100644 --- a/src/google-cloud/google/Context.php +++ b/src/google-cloud/google/Context.php @@ -1,4 +1,5 @@ eventId = $eventId; $this->timestamp = $timestamp; diff --git a/src/google-cloud/google/LegacyEventMapper.php b/src/google-cloud/google/LegacyEventMapper.php index 8614c93..264819d 100644 --- a/src/google-cloud/google/LegacyEventMapper.php +++ b/src/google-cloud/google/LegacyEventMapper.php @@ -1,4 +1,5 @@ [ - 'email' => 'test@nowhere.com', - 'metadata' => [ - 'createdAt' => '2020-05-26T10:42:27Z', - 'lastSignedInAt' => '2020-10-24T11:00:00Z', - ], - 'providerData' => [ - [ 'email' => 'test@nowhere.com', - 'providerId' => 'password', - 'uid' => 'test@nowhere.com', - ], + 'metadata' => [ + 'createdAt' => '2020-05-26T10:42:27Z', + 'lastSignedInAt' => '2020-10-24T11:00:00Z', + ], + 'providerData' => [ + [ + 'email' => 'test@nowhere.com', + 'providerId' => 'password', + 'uid' => 'test@nowhere.com', + ], + ], + 'uid' => 'UUpby3s4spZre6kHsgVSPetzQ8l2', ], - 'uid' => 'UUpby3s4spZre6kHsgVSPetzQ8l2', - ], - 'eventId' => 'aaaaaa-1111-bbbb-2222-cccccccccccc', - 'eventType' => 'providers/firebase.auth/eventTypes/user.create', - 'notSupported' => new \stdClass(), - 'resource' => 'projects/my-project-id', - 'timestamp' => '2020-09-29T11:32:00.000Z', + 'eventId' => 'aaaaaa-1111-bbbb-2222-cccccccccccc', + 'eventType' => 'providers/firebase.auth/eventTypes/user.create', + 'notSupported' => new \stdClass(), + 'resource' => 'projects/my-project-id', + 'timestamp' => '2020-09-29T11:32:00.000Z', ]; $cloudevent = $mapper->fromJsonData($jsonData); diff --git a/src/laravel/src/ConsoleApplicationRunner.php b/src/laravel/src/ConsoleApplicationRunner.php index fe4aca7..4fb8eb2 100644 --- a/src/laravel/src/ConsoleApplicationRunner.php +++ b/src/laravel/src/ConsoleApplicationRunner.php @@ -16,7 +16,7 @@ class ConsoleApplicationRunner implements RunnerInterface private $input; private $output; - public function __construct(ConsoleKernel $application, InputInterface $input, OutputInterface $output = null) + public function __construct(ConsoleKernel $application, InputInterface $input, ?OutputInterface $output = null) { $this->application = $application; $this->input = $input; diff --git a/src/psr-17/tests/phpt/psr15.php b/src/psr-17/tests/phpt/psr15.php index d4c6a1f..0c8834b 100644 --- a/src/psr-17/tests/phpt/psr15.php +++ b/src/psr-17/tests/phpt/psr15.php @@ -7,7 +7,7 @@ require __DIR__.'/autoload.php'; return function (array $context) { - return new class() implements RequestHandlerInterface { + return new class implements RequestHandlerInterface { public function handle(ServerRequestInterface $request): ResponseInterface { return new \Nyholm\Psr7\Response(200, [], 'Hello PSR-15'); diff --git a/src/psr-guzzle/tests/phpt/psr15.php b/src/psr-guzzle/tests/phpt/psr15.php index 5c11de0..d514f88 100644 --- a/src/psr-guzzle/tests/phpt/psr15.php +++ b/src/psr-guzzle/tests/phpt/psr15.php @@ -7,7 +7,7 @@ require __DIR__.'/autoload.php'; return function (array $context) { - return new class() implements RequestHandlerInterface { + return new class implements RequestHandlerInterface { public function handle(ServerRequestInterface $request): ResponseInterface { return new \GuzzleHttp\Psr7\Response(200, [], 'Hello PSR-15'); diff --git a/src/psr-laminas/tests/phpt/psr15.php b/src/psr-laminas/tests/phpt/psr15.php index 8eed26d..361a543 100644 --- a/src/psr-laminas/tests/phpt/psr15.php +++ b/src/psr-laminas/tests/phpt/psr15.php @@ -7,7 +7,7 @@ require __DIR__.'/autoload.php'; return function (array $context) { - return new class() implements RequestHandlerInterface { + return new class implements RequestHandlerInterface { public function handle(ServerRequestInterface $request): ResponseInterface { $response = new \Laminas\Diactoros\Response(); diff --git a/src/psr-nyholm-laminas/tests/phpt/psr15.php b/src/psr-nyholm-laminas/tests/phpt/psr15.php index d4c6a1f..0c8834b 100644 --- a/src/psr-nyholm-laminas/tests/phpt/psr15.php +++ b/src/psr-nyholm-laminas/tests/phpt/psr15.php @@ -7,7 +7,7 @@ require __DIR__.'/autoload.php'; return function (array $context) { - return new class() implements RequestHandlerInterface { + return new class implements RequestHandlerInterface { public function handle(ServerRequestInterface $request): ResponseInterface { return new \Nyholm\Psr7\Response(200, [], 'Hello PSR-15'); diff --git a/src/psr-nyholm/tests/phpt/psr15.php b/src/psr-nyholm/tests/phpt/psr15.php index d4c6a1f..0c8834b 100644 --- a/src/psr-nyholm/tests/phpt/psr15.php +++ b/src/psr-nyholm/tests/phpt/psr15.php @@ -7,7 +7,7 @@ require __DIR__.'/autoload.php'; return function (array $context) { - return new class() implements RequestHandlerInterface { + return new class implements RequestHandlerInterface { public function handle(ServerRequestInterface $request): ResponseInterface { return new \Nyholm\Psr7\Response(200, [], 'Hello PSR-15');