From 9f94a31c79dfaa01273a3ffab0f38e6126acf087 Mon Sep 17 00:00:00 2001 From: Rayan Levert Date: Sat, 17 Aug 2024 07:26:32 +0200 Subject: [PATCH] Arguments : getIterator yields instead of an useless ArrayIterator --- src/Arguments.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Arguments.php b/src/Arguments.php index 3c0de32..18f9b74 100755 --- a/src/Arguments.php +++ b/src/Arguments.php @@ -23,7 +23,7 @@ * * @implements \IteratorAggregate */ -class Arguments implements \IteratorAggregate +class Arguments implements \IteratorAggregate, \Countable { /** * @var array @@ -43,11 +43,11 @@ public function __construct(Argument ...$oArguments) } /** - * @return \Traversable + * @return \Generator */ - public function getIterator(): \Traversable + public function getIterator(): \Generator { - return new \ArrayIterator($this->data); + yield from $this->data; } /** @@ -121,7 +121,7 @@ public function parse(string ...$arguments): void } // Loops to recover required arguments and set their values - foreach ($this->data as $name => $oArgument) { + foreach ($this as $name => $oArgument) { if (!$oArgument->isRequired()) { continue; } @@ -171,7 +171,7 @@ public function getRequired(): self $oSelf = new self(); - foreach ($this->data as $oArgument) { + foreach ($this as $oArgument) { if ($oArgument->isRequired()) { $oSelf->set($oArgument); } @@ -215,7 +215,7 @@ public function printArguments(): void */ protected function getByShortPrefix(string $name): ?Argument { - foreach ($this->data as $oArgument) { + foreach ($this as $oArgument) { if ($oArgument->getPrefix() === $name) { return $oArgument; } @@ -229,7 +229,7 @@ protected function getByShortPrefix(string $name): ?Argument */ protected function getByLongPrefix(string $name): ?Argument { - foreach ($this->data as $oArgument) { + foreach ($this as $oArgument) { if ($oArgument->getLongPrefix() === $name) { return $oArgument; } @@ -245,7 +245,7 @@ protected function getNotHandled(): self { $oSelf = new self(); - foreach ($this->data as $oArgument) { + foreach ($this as $oArgument) { if (!$oArgument->hasBeenHandled()) { $oSelf->set($oArgument); } @@ -269,7 +269,7 @@ protected function assertOrderRequired(): void { $argHasNotRequired = false; - foreach ($this->data as $name => $oArgument) { + foreach ($this as $name => $oArgument) { if ($oArgument->getPrefix() || $oArgument->getLongPrefix()) { continue; }