| Total Complexity | 4 | 
| Total Lines | 34 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php | ||
| 22 | class ErrorCollectionIterator implements IteratorAggregate | ||
| 23 | { | ||
| 24 | /** | ||
| 25 | * @var ErrorRenderer|callable | ||
| 26 | * @phpstan-var ErrorRenderer|(callable(Error,string $attribute,ErrorCollection):string) | ||
| 27 | */ | ||
| 28 | private $render_error; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * @phpstan-param ErrorRenderer|(callable(Error,string $attribute,ErrorCollection):string)|null $render_error | ||
| 32 | */ | ||
| 33 | public function __construct( | ||
| 34 | private readonly ErrorCollection $collection, | ||
| 35 | ErrorRenderer|callable $render_error = null | ||
| 36 |     ) { | ||
| 37 | $this->render_error = $render_error ?? fn(Error $error) => (string) $error; | ||
| 38 | } | ||
| 39 | |||
| 40 | /** | ||
| 41 | * @return Traversable<string, string> | ||
| 42 | */ | ||
| 43 | public function getIterator(): Traversable | ||
| 44 |     { | ||
| 45 |         foreach ($this->collection as $attribute => $error) { | ||
| 46 | yield $attribute => $this->render_error($error, $attribute); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Renders an error into a string. | ||
| 52 | */ | ||
| 53 | private function render_error(Error $error, string $attribute): string | ||
| 56 | } | ||
| 57 | } | ||
| 58 |