Skip to content

Commit

Permalink
Use impure to mark hasNext in iterator (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtk3d committed Sep 19, 2023
1 parent e5c7193 commit 6c0f492
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 0 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ parameters:
count: 1
path: src/Collection/Stream/Collectors.php

-
message: "#Unreachable statement - code above always terminates.#"
count: 1
path: src/Collection/Iterator.php

-
message: "#Template type T of method#"
count: 6
Expand Down
5 changes: 4 additions & 1 deletion src/Collection/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public static function fromIterable(iterable $elements): self
return new ArrayIterator($elements);
}

/**
* @phpstan-impure
*/
public function hasNext(): bool
{
return !$this->current->isEmpty();
Expand Down Expand Up @@ -140,7 +143,7 @@ public function reduce(callable $operation)
}

$accumulator = $this->next();
while ($this->hasNext()) { // @phpstan-ignore-line
while ($this->hasNext()) {
$accumulator = $operation($accumulator, $this->next());
}

Expand Down

0 comments on commit 6c0f492

Please sign in to comment.