From 9beaa98db448de5d7efcb1a2bd12231f1eebfbb8 Mon Sep 17 00:00:00 2001 From: Martin Rademacher Date: Mon, 20 Jun 2022 11:53:03 +1200 Subject: [PATCH] Address PHP 8.2. warnings and static analysis (#1263) * Address PHP 8.2. warnings * Supress UndefinedAttributeClass error for AllowDynamicProperties --- phpstan-baseline.neon | 5 +++++ psalm.xml | 6 ++++++ src/Context.php | 4 +++- tests/Annotations/AbstractAnnotationTest.php | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f0a6e99d5..fc1ba7e3f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -40,6 +40,11 @@ parameters: count: 1 path: src/Annotations/Schema.php + - + message: "#^Attribute class AllowDynamicProperties does not exist\\.$#" + count: 1 + path: src/Context.php + - message: "#^Ternary operator condition is always true\\.$#" count: 1 diff --git a/psalm.xml b/psalm.xml index e9e027b01..670466060 100644 --- a/psalm.xml +++ b/psalm.xml @@ -18,5 +18,11 @@ + + + + + + diff --git a/src/Context.php b/src/Context.php index 30ab050e3..7b15d7b84 100644 --- a/src/Context.php +++ b/src/Context.php @@ -8,6 +8,7 @@ use OpenApi\Annotations\OpenApi; use OpenApi\Loggers\DefaultLogger; +use Psr\Log\LoggerInterface; /** * Context. @@ -44,10 +45,11 @@ * the serializer * @property Annotations\AbstractAnnotation|null $nested * @property Annotations\AbstractAnnotation[]|null $annotations - * @property \Psr\Log\LoggerInterface|null $logger Guaranteed to be set when using the `Generator` + * @property LoggerInterface|null $logger Guaranteed to be set when using the `Generator` * @property array|null $scanned Details of file scanner when using ReflectionAnalyser * @property string|null $version The OpenAPI version in use */ +#[\AllowDynamicProperties] class Context { /** diff --git a/tests/Annotations/AbstractAnnotationTest.php b/tests/Annotations/AbstractAnnotationTest.php index 816e31d58..861ad4436 100644 --- a/tests/Annotations/AbstractAnnotationTest.php +++ b/tests/Annotations/AbstractAnnotationTest.php @@ -22,6 +22,9 @@ public function testVendorFields(): void $this->assertSame(123, $output->$prefixedProperty); } + /** + * @requires PHP < 8.2 + */ public function testInvalidField(): void { $this->assertOpenApiLogEntryContains('Unexpected field "doesnot" for @OA\Get(), expecting');