Skip to content

Commit

Permalink
Add EmptyIterator stub
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jun 24, 2022
1 parent b614619 commit 4a880d1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions stubs/iterable.stub
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,23 @@ class RegexIterator extends FilterIterator {
*/
public function key() {}
}

/**
* @template-implements Iterator<never, never>
*/
class EmptyIterator implements Iterator {
/**
* @return never
*/
public function current() {}

/**
* @return never
*/
public function key() {}

/**
* @return false
*/
public function valid() {}
}
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4117.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7490.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/remember-possibly-impure-function-values.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/emptyiterator.php');
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/data/emptyiterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace EmptyIteratorTest;

use function PHPStan\Testing\assertType;

class Foo
{
public function doFoo(\EmptyIterator $it): void
{
assertType('EmptyIterator', $it);
assertType('*NEVER*', $it->key());
assertType('*NEVER*', $it->current());
assertType('void', $it->next());
assertType('false', $it->valid());
}

}

0 comments on commit 4a880d1

Please sign in to comment.