Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| BoundedContextHashmap | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
9 | |
100.00% |
1 / 1 |
| offsetGet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTupleIterator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getBoundedContextFromClassName | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
7 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\BoundedContext; |
| 3 | |
| 4 | use Apie\Core\Actions\BoundedContextHashmapIterator; |
| 5 | use Apie\Core\Entities\EntityInterface; |
| 6 | use Apie\Core\Identifiers\IdentifierInterface; |
| 7 | use Apie\Core\Lists\ItemHashmap; |
| 8 | use ReflectionClass; |
| 9 | |
| 10 | /** |
| 11 | * Contains multiple bounded contexts mapped by key. |
| 12 | */ |
| 13 | final class BoundedContextHashmap extends ItemHashmap |
| 14 | { |
| 15 | protected bool $mutable = false; |
| 16 | |
| 17 | public function offsetGet(mixed $offset): BoundedContext |
| 18 | { |
| 19 | return parent::offsetGet($offset); |
| 20 | } |
| 21 | |
| 22 | public function getTupleIterator(): BoundedContextHashmapIterator |
| 23 | { |
| 24 | return new BoundedContextHashmapIterator($this); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @param ReflectionClass<EntityInterface|IdentifierInterface<EntityInterface>> $class |
| 29 | */ |
| 30 | public function getBoundedContextFromClassName(ReflectionClass $class, ?BoundedContextId $prio = null): ?BoundedContext |
| 31 | { |
| 32 | if ($class->implementsInterface(IdentifierInterface::class)) { |
| 33 | $class = $class->getMethod('getReferenceFor')->invoke(null); |
| 34 | } |
| 35 | if ($prio && isset($this[$prio->toNative()])) { |
| 36 | $boundedContext = $this[$prio->toNative()]; |
| 37 | if ($boundedContext->contains($class)) { |
| 38 | return $boundedContext; |
| 39 | } |
| 40 | } |
| 41 | foreach ($this as $boundedContext) { |
| 42 | if ($boundedContext->contains($class)) { |
| 43 | return $boundedContext; |
| 44 | } |
| 45 | } |
| 46 | return null; |
| 47 | } |
| 48 | } |