Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.00% |
19 / 20 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
| BoundedContextHashmapIterator | |
95.00% |
19 / 20 |
|
83.33% |
5 / 6 |
8 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| current | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| key | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| next | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |||
| rewind | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| valid | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Actions; |
| 3 | |
| 4 | use Apie\Core\BoundedContext\BoundedContext; |
| 5 | use Apie\Core\BoundedContext\BoundedContextHashmap; |
| 6 | use Apie\Core\Entities\EntityInterface; |
| 7 | use Iterator; |
| 8 | use ReflectionClass; |
| 9 | |
| 10 | /** |
| 11 | * @implements Iterator<int, BoundedContextEntityTuple> |
| 12 | */ |
| 13 | class BoundedContextHashmapIterator implements Iterator |
| 14 | { |
| 15 | private int $counter = 0; |
| 16 | private ?BoundedContext $currentBoundedContext = null; |
| 17 | /** |
| 18 | * @var ReflectionClass<EntityInterface>|null |
| 19 | */ |
| 20 | private ?ReflectionClass $currentValue = null; |
| 21 | /** |
| 22 | * @var array<int, BoundedContext> |
| 23 | */ |
| 24 | private array $boundedContextTodo = []; |
| 25 | |
| 26 | /** |
| 27 | * @var array<int, ReflectionClass<EntityInterface>> |
| 28 | */ |
| 29 | private array $entityTodo = []; |
| 30 | |
| 31 | public function __construct(private readonly BoundedContextHashmap $boundedContextHashmap) |
| 32 | { |
| 33 | } |
| 34 | public function current(): ?BoundedContextEntityTuple |
| 35 | { |
| 36 | return new BoundedContextEntityTuple( |
| 37 | $this->currentBoundedContext, |
| 38 | $this->currentValue |
| 39 | ); |
| 40 | } |
| 41 | public function key(): int |
| 42 | { |
| 43 | return $this->counter; |
| 44 | } |
| 45 | public function next(): void |
| 46 | { |
| 47 | $this->currentValue = null; |
| 48 | while (empty($this->entityTodo)) { |
| 49 | $boundedContext = array_shift($this->boundedContextTodo); |
| 50 | if (!$boundedContext) { |
| 51 | return; |
| 52 | } |
| 53 | $this->currentBoundedContext = $boundedContext; |
| 54 | $this->entityTodo = $this->currentBoundedContext->resources->toArray(); |
| 55 | } |
| 56 | $this->counter++; |
| 57 | $this->currentValue = array_shift($this->entityTodo); |
| 58 | } |
| 59 | public function rewind(): void |
| 60 | { |
| 61 | $this->counter = 0; |
| 62 | $this->boundedContextTodo = $this->boundedContextHashmap->toArray(); |
| 63 | $this->entityTodo = []; |
| 64 | $this->next(); |
| 65 | } |
| 66 | public function valid(): bool |
| 67 | { |
| 68 | return null !== $this->currentValue; |
| 69 | } |
| 70 | } |