Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.33% covered (success)
93.33%
14 / 15
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
GeneratedCode
93.33% covered (success)
93.33%
14 / 15
75.00% covered (warning)
75.00%
3 / 4
6.01
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
 addTodo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasTodos
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNextTodo
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
1<?php
2namespace Apie\StorageMetadataBuilder\Mediators;
3
4use Apie\Core\Actions\BoundedContextEntityTuple;
5use Apie\Core\BoundedContext\BoundedContext;
6use Apie\Core\BoundedContext\BoundedContextHashmap;
7use Apie\Core\Lists\ReflectionClassList;
8use Apie\Core\Lists\ReflectionMethodList;
9use Apie\StorageMetadataBuilder\Lists\GeneratedCodeHashmap;
10use Apie\StorageMetadataBuilder\Resources\GeneratedCodeTimestamp;
11use ReflectionClass;
12use RuntimeException;
13
14final class GeneratedCode
15{
16    /**
17     * @var GeneratedCodeContext[] $todo
18     */
19    private array $todo = [];
20
21    public function __construct(
22        public readonly BoundedContextHashmap $boundedContextHashmap,
23        public readonly GeneratedCodeHashmap $generatedCodeHashmap
24    ) {
25        foreach ($boundedContextHashmap->getTupleIterator() as $boundedContextTuple) {
26            $this->todo[] = new GeneratedCodeContext($this, $boundedContextTuple);
27        }
28        $this->todo[] = new GeneratedCodeContext(
29            $this,
30            new BoundedContextEntityTuple(
31                new BoundedContext('core', new ReflectionClassList(), new ReflectionMethodList()),
32                new ReflectionClass(GeneratedCodeTimestamp::class)
33            )
34        );
35    }
36
37    public function addTodo(GeneratedCodeContext $context)
38    {
39        $this->todo[] = $context;
40    }
41
42    public function hasTodos(): bool
43    {
44        return count($this->todo) > 0;
45    }
46
47    public function getNextTodo(): GeneratedCodeContext
48    {
49        $current = array_pop($this->todo);
50        if ($current instanceof GeneratedCodeContext) {
51            return $current;
52        }
53        throw new RuntimeException('I have no TODOs anymore');
54    }
55}