Skip to content

Commit

Permalink
Gh 2585: try again: iterable (#2595)
Browse files Browse the repository at this point in the history
* Revert "Revert "Gh 2585 (#2592)""

This reverts commit 8047982.

* Explicit type
  • Loading branch information
dantleech committed Mar 9, 2024
1 parent 8047982 commit cf25900
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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

0 comments on commit cf25900

Please sign in to comment.