From 6c0f492f94728ba5f039396a8dd9fd969a271d31 Mon Sep 17 00:00:00 2001 From: Mateusz Cholewka Date: Tue, 19 Sep 2023 19:30:19 +0200 Subject: [PATCH] Use impure to mark hasNext in iterator (#78) --- phpstan.neon | 5 ----- src/Collection/Iterator.php | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 71e5eef..2ea78e5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -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 diff --git a/src/Collection/Iterator.php b/src/Collection/Iterator.php index 8d87257..2b03633 100644 --- a/src/Collection/Iterator.php +++ b/src/Collection/Iterator.php @@ -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(); @@ -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()); }