Merge "Make interface compatible with RecursiveIterator"

This commit is contained in:
jenkins-bot 2022-07-13 08:36:12 +00:00 committed by Gerrit Code Review
commit 48436ddc70
2 changed files with 9 additions and 8 deletions

View file

@ -21,7 +21,7 @@ class EchoMultipleIterator implements RecursiveIterator {
$this->children = $children;
}
public function rewind() {
public function rewind(): void {
$this->active = $this->children;
$this->key = 0;
foreach ( $this->active as $key => $it ) {
@ -32,11 +32,11 @@ class EchoMultipleIterator implements RecursiveIterator {
}
}
public function valid() {
public function valid(): bool {
return (bool)$this->active;
}
public function next() {
public function next(): void {
$this->key++;
foreach ( $this->active as $key => $it ) {
$it->next();
@ -46,6 +46,7 @@ class EchoMultipleIterator implements RecursiveIterator {
}
}
#[\ReturnTypeWillChange]
public function current() {
$result = [];
foreach ( $this->active as $it ) {
@ -55,15 +56,15 @@ class EchoMultipleIterator implements RecursiveIterator {
return $result;
}
public function key() {
public function key(): int {
return $this->key;
}
public function hasChildren() {
public function hasChildren(): bool {
return (bool)$this->active;
}
public function getChildren() {
public function getChildren(): ?RecursiveIterator {
// The NotRecursiveIterator is used rather than a RecursiveArrayIterator
// so that nested arrays dont get recursed.
return new EchoNotRecursiveIterator( new ArrayIterator( $this->current() ) );

View file

@ -8,11 +8,11 @@
* than the wrapped iterator.
*/
class EchoNotRecursiveIterator extends IteratorDecorator implements RecursiveIterator {
public function hasChildren() {
public function hasChildren(): bool {
return false;
}
public function getChildren() {
public function getChildren(): ?RecursiveIterator {
// @phan-suppress-next-line PhanTypeMismatchReturnProbablyReal Never called
return null;
}