Skip to content

Commit

Permalink
Arguments : getIterator yields instead of an useless ArrayIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
rayanlevert committed Aug 17, 2024
1 parent bcb5560 commit 9f94a31
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @implements \IteratorAggregate<string, Argument>
*/
class Arguments implements \IteratorAggregate
class Arguments implements \IteratorAggregate, \Countable
{
/**
* @var array<string, Argument>
Expand All @@ -43,11 +43,11 @@ public function __construct(Argument ...$oArguments)
}

/**
* @return \Traversable<string, Argument>
* @return \Generator<string, Argument>
*/
public function getIterator(): \Traversable
public function getIterator(): \Generator
{
return new \ArrayIterator($this->data);
yield from $this->data;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 9f94a31

Please sign in to comment.