-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathProcessingErrors.php
More file actions
43 lines (35 loc) · 909 Bytes
/
ProcessingErrors.php
File metadata and controls
43 lines (35 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Flowpack\NodeTemplates\Domain\ErrorHandling;
/** @implements \IteratorAggregate<int, ProcessingError> */
class ProcessingErrors implements \IteratorAggregate
{
/** @var array<int, ProcessingError> */
private array $errors = [];
private function __construct()
{
}
public static function create(): self
{
return new self();
}
/** @phpstan-assert-if-true !null $this->first() */
public function hasError(): bool
{
return $this->errors !== [];
}
public function add(ProcessingError $error): void
{
$this->errors[] = $error;
}
public function first(): ?ProcessingError
{
return $this->errors[0] ?? null;
}
/**
* @return \Traversable<int, ProcessingError>|ProcessingError[]
*/
public function getIterator(): \Traversable
{
yield from $this->errors;
}
}