Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ExpandsTranslationWithBoundedContext | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
6 | |
100.00% |
1 / 1 |
| iterateOverTranslationWithAllResources | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\Common\Concerns; |
| 3 | |
| 4 | use Apie\Core\BoundedContext\BoundedContextHashmap; |
| 5 | use Apie\Core\Context\ApieContext; |
| 6 | use Apie\Core\Identifiers\SnakeCaseSlug; |
| 7 | use Apie\Core\Translator\ValueObjects\AbstractTranslation; |
| 8 | use Generator; |
| 9 | |
| 10 | trait ExpandsTranslationWithBoundedContext |
| 11 | { |
| 12 | /** |
| 13 | * @param iterable<int, AbstractTranslation> $translations |
| 14 | * @return Generator<int, AbstractTranslation> |
| 15 | */ |
| 16 | protected function iterateOverTranslationWithAllResources( |
| 17 | ApieContext $apieContext, |
| 18 | iterable $translations, |
| 19 | bool $includeWithoutBoundedContext |
| 20 | ): Generator { |
| 21 | if ($includeWithoutBoundedContext) { |
| 22 | foreach ($translations as $translation) { |
| 23 | yield $translation |
| 24 | ->withoutBoundedContextId() |
| 25 | ->withoutResourceIdentifier(); |
| 26 | } |
| 27 | } |
| 28 | $hashmap = $apieContext->getContext(BoundedContextHashmap::class, false); |
| 29 | if ($hashmap instanceof BoundedContextHashmap) { |
| 30 | foreach ($hashmap->getTupleIterator() as $tuple) { |
| 31 | foreach ($translations as $translation) { |
| 32 | yield $translation |
| 33 | ->withBoundedContextId($tuple->boundedContext->getId()) |
| 34 | ->withResourceIdentifier(SnakeCaseSlug::fromClass($tuple->resourceClass)); |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | } |