From 35340d40057f1533687268997262185fdcff9084 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Fri, 20 Jan 2023 16:45:34 +1300 Subject: [PATCH] API Strongly type iterator classes and remove ReturnTypeWillChange annotation --- src/Utils/CombinationsArrayIterator.php | 17 ++++++----------- src/Utils/MultipleArrayIterator.php | 15 +++++---------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/Utils/CombinationsArrayIterator.php b/src/Utils/CombinationsArrayIterator.php index 1cf2806..110f9c4 100644 --- a/src/Utils/CombinationsArrayIterator.php +++ b/src/Utils/CombinationsArrayIterator.php @@ -32,29 +32,26 @@ class CombinationsArrayIterator implements Iterator $this->rewind(); } - #[\ReturnTypeWillChange] - public function rewind() + public function rewind(): void { if (!$this->numArrays) { $this->isValid = false; } else { $this->isValid = true; $this->k = 0; - + for ($i = 0; $i < $this->numArrays; $i++) { reset($this->arrays[$i]); } } } - #[\ReturnTypeWillChange] - public function valid() + public function valid(): bool { return $this->isValid; } - #[\ReturnTypeWillChange] - public function next() + public function next(): void { $this->k++; @@ -71,8 +68,7 @@ class CombinationsArrayIterator implements Iterator } } - #[\ReturnTypeWillChange] - public function current() + public function current(): mixed { $res = array(); for ($i = 0; $i < $this->numArrays; $i++) { @@ -81,8 +77,7 @@ class CombinationsArrayIterator implements Iterator return $res; } - #[\ReturnTypeWillChange] - public function key() + public function key(): mixed { return $this->k; } diff --git a/src/Utils/MultipleArrayIterator.php b/src/Utils/MultipleArrayIterator.php index 1d94ee0..f1bba51 100644 --- a/src/Utils/MultipleArrayIterator.php +++ b/src/Utils/MultipleArrayIterator.php @@ -22,8 +22,7 @@ class MultipleArrayIterator implements Iterator $this->rewind(); } - #[\ReturnTypeWillChange] - public function rewind() + public function rewind(): void { $this->active = $this->arrays; if ($this->active) { @@ -31,20 +30,17 @@ class MultipleArrayIterator implements Iterator } } - #[\ReturnTypeWillChange] - public function current() + public function current(): mixed { return $this->active ? current($this->active[0]) : false; } - #[\ReturnTypeWillChange] - public function key() + public function key(): mixed { return $this->active ? key($this->active[0]) : false; } - #[\ReturnTypeWillChange] - public function next() + public function next(): void { if (!$this->active) { return; @@ -58,8 +54,7 @@ class MultipleArrayIterator implements Iterator } } - #[\ReturnTypeWillChange] - public function valid() + public function valid(): bool { return $this->active && (current($this->active[0] ?? []) !== false); }