From ac4f51f66d1804296e08bada2565eade2a720fce Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 9 Oct 2023 18:10:27 +0200 Subject: [PATCH] Implement `IteratorAggregate` to delegate iteration of the available label pickers --- .../system/label/LabelPickerGroup.class.php | 29 ++----------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php b/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php index 15984d6447..2df533ef87 100644 --- a/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php +++ b/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php @@ -15,7 +15,7 @@ use wcf\system\database\util\PreparedStatementConditionBuilder; * @license GNU Lesser General Public License * @since 6.1 */ -final class LabelPickerGroup implements \Countable, \Iterator +final class LabelPickerGroup implements \Countable, \IteratorAggregate { /** * @var LabelPicker[] @@ -27,8 +27,6 @@ final class LabelPickerGroup implements \Countable, \Iterator */ private readonly array $positionToGroupID; - private int $position = 0; - /** * @param LabelPicker[] $labelPickers */ @@ -204,30 +202,9 @@ final class LabelPickerGroup implements \Countable, \Iterator return \count($this->labelPickers); } - public function current(): LabelPicker - { - $groupID = $this->positionToGroupID[$this->position]; - return $this->labelPickers[$groupID]; - } - - public function key(): int - { - return $this->position; - } - - public function next(): void - { - $this->position++; - } - - public function rewind(): void - { - $this->position = 0; - } - - public function valid(): bool + public function getIterator(): \Traversable { - return isset($this->positionToGroupID[$this->position]); + return new \ArrayIterator($this->labelPickers); } /** -- 2.20.1