From 82b025d574e7122e4a7074ba91cc158c5c2f4f6e Mon Sep 17 00:00:00 2001 From: Daniel Leech Date: Sat, 9 Mar 2024 13:33:58 +0000 Subject: [PATCH 1/2] Revert "Revert "Gh 2585 (#2592)"" This reverts commit 8047982edba8ccb22e4d803bd35e0958883695ef. --- CHANGELOG.md | 1 + .../DocblockMissingParamProvider.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dded42312..e325a38a4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Improvements: - Disable the processing of includes/requires, it doesn't work very well but it has massive performance impact on certain projects #2580 - Include project PHP and runtime version and LSP status + - Add `iterable` "generic" `@param` in docblock #2585 Bug fixes: diff --git a/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/DocblockMissingParamProvider.php b/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/DocblockMissingParamProvider.php index 93a45b6325..018a40384c 100644 --- a/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/DocblockMissingParamProvider.php +++ b/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/DocblockMissingParamProvider.php @@ -20,6 +20,7 @@ use Phpactor\WorseReflection\Core\Type\ClosureType; use Phpactor\WorseReflection\Core\Type\MissingType; use Phpactor\WorseReflection\Core\Type\MixedType; +use Phpactor\WorseReflection\Core\Type\PseudoIterableType; use Phpactor\WorseReflection\Core\Type\ReflectedClassType; use Phpactor\WorseReflection\Core\Util\NodeUtil; @@ -94,6 +95,9 @@ public function exit(NodeContextResolver $resolver, Frame $frame, Node $node): i if ($type instanceof ArrayType) { $type = new ArrayType(TypeFactory::int(), TypeFactory::mixed()); } + if ($type instanceof PseudoIterableType) { + $type = new PseudoIterableType(TypeFactory::int(), TypeFactory::mixed()); + } // replace with "mixed" $type = $type->map(fn (Type $type) => $type instanceof MissingType ? new MixedType() : $type); @@ -171,6 +175,24 @@ public function foo(Generator $foobar) { Assert::assertEquals('Method "foo" is missing @param $foobar', $diagnostics->at(0)->message()); } ); + yield new DiagnosticExample( + title: 'iterable', + source: <<<'PHP' + byClass(DocblockMissingParamDiagnostic::class); + Assert::assertCount(1, $diagnostics); + Assert::assertEquals('Method "foo" is missing @param $foobar', $diagnostics->at(0)->message()); + } + ); yield new DiagnosticExample( title: 'array', source: <<<'PHP' From 063f3f9cd0134f90bffeba955c2ac9e2c044df56 Mon Sep 17 00:00:00 2001 From: Daniel Leech Date: Sat, 9 Mar 2024 13:35:14 +0000 Subject: [PATCH 2/2] Explicit type --- .../TolerantParser/Diagnostics/DocblockMissingParamProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/DocblockMissingParamProvider.php b/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/DocblockMissingParamProvider.php index 018a40384c..268551dc1d 100644 --- a/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/DocblockMissingParamProvider.php +++ b/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/DocblockMissingParamProvider.php @@ -95,7 +95,7 @@ public function exit(NodeContextResolver $resolver, Frame $frame, Node $node): i if ($type instanceof ArrayType) { $type = new ArrayType(TypeFactory::int(), TypeFactory::mixed()); } - if ($type instanceof PseudoIterableType) { + if ($type::class === PseudoIterableType::class) { $type = new PseudoIterableType(TypeFactory::int(), TypeFactory::mixed()); }