From 2109fdaf4ae883f9012abef24a2c1a4037d93982 Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Thu, 9 Jan 2025 15:11:00 +1300 Subject: [PATCH] Fix phpstan2 and psalm5 issues --- composer.json | 2 +- phpstan-baseline.neon | 6 ------ psalm-baseline.xml | 8 +------- psalm.xml | 2 ++ src/Analysers/TokenScanner.php | 1 + tests/Processors/AugmentSchemasTest.php | 4 ++-- tests/Processors/MergeJsonContentTest.php | 4 ++-- tests/Processors/MergeXmlContentTest.php | 4 ++-- 8 files changed, 11 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index f142d885a..cce4885c1 100644 --- a/composer.json +++ b/composer.json @@ -108,7 +108,7 @@ ], "analyse": [ "export XDEBUG_MODE=off && phpstan analyse --memory-limit=2G", - "export XDEBUG_MODE=off && psalm" + "export XDEBUG_MODE=off && psalm --threads=1" ], "spectral-examples": "for ff in `find Examples -name '*.yaml'`; do spectral lint $ff; done", "spectral-scratch": "for ff in `find tests/Fixtures/Scratch -name '*.yaml'`; do spectral lint $ff; done", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3a6b267d9..19f8bf8e9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -24,12 +24,6 @@ parameters: count: 1 path: src/Analysers/ReflectionAnalyser.php - - - message: '#^Call to function array_key_exists\(\) with string and array\{\} will always evaluate to false\.$#' - identifier: function.impossibleType - count: 1 - path: src/Analysers/TokenScanner.php - - message: '#^Access to an undefined property OpenApi\\Annotations\\AbstractAnnotation\:\:\$description\.$#' identifier: property.notFound diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 7f2edd1ea..5c064bb4b 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,8 +1,2 @@ - - - - Yaml::parse($contents) - - - + diff --git a/psalm.xml b/psalm.xml index 670466060..0f3330cff 100644 --- a/psalm.xml +++ b/psalm.xml @@ -6,6 +6,8 @@ xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorBaseline="psalm-baseline.xml" + findUnusedBaselineEntry="true" + findUnusedCode="false" phpVersion="8.1" > diff --git a/src/Analysers/TokenScanner.php b/src/Analysers/TokenScanner.php index 2367d260d..3f4896a7d 100644 --- a/src/Analysers/TokenScanner.php +++ b/src/Analysers/TokenScanner.php @@ -50,6 +50,7 @@ public function scanFile(string $filename): array protected function collect_stmts(array $stmts, string $namespace): array { + /** @var array $uses */ $uses = []; $resolve = function (string $name) use ($namespace, &$uses) { if (array_key_exists($name, $uses)) { diff --git a/tests/Processors/AugmentSchemasTest.php b/tests/Processors/AugmentSchemasTest.php index 0125249d3..6162ea97f 100644 --- a/tests/Processors/AugmentSchemasTest.php +++ b/tests/Processors/AugmentSchemasTest.php @@ -32,7 +32,7 @@ public function testAugmentSchemas(): void $this->assertSame('Customer', $customer->schema, '@OA\Schema()->schema based on classname'); $this->assertIsArray($customer->properties); - $this->assertCount(10, $customer->properties, '@OA\Property()s are merged into the @OA\Schema of the class'); + $this->assertCount(10, (array) $customer->properties, '@OA\Property()s are merged into the @OA\Schema of the class'); } public function testAugmentSchemasForInterface(): void @@ -51,6 +51,6 @@ public function testAugmentSchemasForInterface(): void $analysis->process([new AugmentSchemas()]); $this->assertIsArray($customer->properties); - $this->assertCount(9, $customer->properties, '@OA\Property()s are merged into the @OA\Schema of the class'); + $this->assertCount(9, (array) $customer->properties, '@OA\Property()s are merged into the @OA\Schema of the class'); } } diff --git a/tests/Processors/MergeJsonContentTest.php b/tests/Processors/MergeJsonContentTest.php index 31a524552..ff9edc527 100644 --- a/tests/Processors/MergeJsonContentTest.php +++ b/tests/Processors/MergeJsonContentTest.php @@ -32,7 +32,7 @@ public function testJsonContent(): void $analysis->process([new MergeJsonContent()]); $this->assertIsArray($response->content); - $this->assertCount(1, $response->content); + $this->assertCount(1, (array) $response->content); $this->assertCount(0, $response->_unmerged); $json = json_decode(json_encode($response), true); $this->assertSame('#/components/schemas/repository', $json['content']['application/json']['schema']['items']['$ref']); @@ -75,7 +75,7 @@ public function testParameter(): void $analysis->process([new MergeJsonContent()]); $this->assertIsArray($parameter->content); - $this->assertCount(1, $parameter->content); + $this->assertCount(1, (array) $parameter->content); $this->assertCount(0, $parameter->_unmerged); $json = json_decode(json_encode($parameter), true); $this->assertSame('query', $json['in']); diff --git a/tests/Processors/MergeXmlContentTest.php b/tests/Processors/MergeXmlContentTest.php index c0f2286c7..8670c5c83 100644 --- a/tests/Processors/MergeXmlContentTest.php +++ b/tests/Processors/MergeXmlContentTest.php @@ -32,7 +32,7 @@ public function testXmlContent(): void $analysis->process([new MergeXmlContent()]); $this->assertIsArray($response->content); - $this->assertCount(1, $response->content); + $this->assertCount(1, (array) $response->content); $this->assertCount(0, $response->_unmerged); $json = json_decode(json_encode($response), true); $this->assertSame('#/components/schemas/repository', $json['content']['application/xml']['schema']['items']['$ref']); @@ -73,7 +73,7 @@ public function testParameter(): void $analysis->process([new MergeXmlContent()]); $this->assertIsArray($parameter->content); - $this->assertCount(1, $parameter->content); + $this->assertCount(1, (array) $parameter->content); $this->assertCount(0, $parameter->_unmerged); $json = json_decode(json_encode($parameter), true); $this->assertSame('query', $json['in']);