Implement `IteratorAggregate` to delegate iteration of the available label pickers
authorAlexander Ebert <ebert@woltlab.com>
Mon, 9 Oct 2023 16:10:27 +0000 (18:10 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 9 Oct 2023 16:10:27 +0000 (18:10 +0200)
wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php

index 15984d6447651976c93ea93671ee35ca70bb77a5..2df533ef870dbcb56cadb30f056d59cd6d3834c0 100644 (file)
@@ -15,7 +15,7 @@ use wcf\system\database\util\PreparedStatementConditionBuilder;
  * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @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);
     }
 
     /**