Skip to content
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

Gh 2585: try again: iterable #2595

Merged
merged 2 commits into from Mar 9, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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:

Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -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::class === PseudoIterableType::class) {
$type = new PseudoIterableType(TypeFactory::int(), TypeFactory::mixed());
}

// replace <undefined> with "mixed"
$type = $type->map(fn (Type $type) => $type instanceof MissingType ? new MixedType() : $type);
Expand Down Expand Up @@ -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'
<?php

class Foobar
{
public function foo(iterable $foobar) {
}
}
PHP,
valid: false,
assertion: function (Diagnostics $diagnostics): void {
$diagnostics = $diagnostics->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'
Expand Down