Skip to content

Commit 46bb70c

Browse files
aymanrbclaude
andcommitted
Implement IteratorAggregate and Countable on ParseResult
Users previously had to call getParsedRawData() to iterate over results or countResults() for counting. ParseResult now implements \IteratorAggregate and \Countable so it can be used directly in foreach loops and with count(), reducing boilerplate in consumer code. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent edc3712 commit 46bb70c

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/ParseResult.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use aymanrb\UnstructuredTextParser\Exception\InvalidParsedDataKeyException;
88

9-
class ParseResult
9+
class ParseResult implements \IteratorAggregate, \Countable
1010
{
1111
private array $parsedRawData = [];
1212

@@ -38,6 +38,16 @@ public function countResults(): int
3838
return count($this->parsedRawData);
3939
}
4040

41+
public function count(): int
42+
{
43+
return $this->countResults();
44+
}
45+
46+
public function getIterator(): \ArrayIterator
47+
{
48+
return new \ArrayIterator($this->parsedRawData);
49+
}
50+
4151
public function keyExists(string $key): bool
4252
{
4353
return array_key_exists($key, $this->parsedRawData);

0 commit comments

Comments
 (0)