Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| TranslationAware | |
85.71% |
6 / 7 |
|
80.00% |
4 / 5 |
5.07 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTranslation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setText | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getText | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\IntegrationTests\Apie\TypeDemo\Resources; |
| 3 | |
| 4 | use Apie\Core\Attributes\StoreOptions; |
| 5 | use Apie\Core\Entities\EntityInterface; |
| 6 | use Apie\Core\Lists\StringHashmap; |
| 7 | use Apie\Core\Translator\ValueObjects\AbstractTranslation; |
| 8 | use Apie\IanaValueObjects\LanguageAndRegion; |
| 9 | use Apie\IntegrationTests\Apie\TypeDemo\Identifiers\TranslationAwareIdentifier; |
| 10 | |
| 11 | class TranslationAware implements EntityInterface |
| 12 | { |
| 13 | private TranslationAwareIdentifier $id; |
| 14 | |
| 15 | #[StoreOptions(mutableListField: true)] |
| 16 | private StringHashmap $translations; |
| 17 | |
| 18 | public function __construct( |
| 19 | private readonly AbstractTranslation $translation |
| 20 | ) { |
| 21 | $this->id = TranslationAwareIdentifier::createRandom(); |
| 22 | $this->translations = (new StringHashmap())->toMutable(); |
| 23 | } |
| 24 | |
| 25 | public function getId(): TranslationAwareIdentifier |
| 26 | { |
| 27 | return $this->id; |
| 28 | } |
| 29 | |
| 30 | public function getTranslation(): AbstractTranslation |
| 31 | { |
| 32 | return $this->translation; |
| 33 | } |
| 34 | |
| 35 | public function setText(LanguageAndRegion $language, string $text): TranslationAware |
| 36 | { |
| 37 | $this->translations[$language->toNative()] = $text; |
| 38 | |
| 39 | return $this; |
| 40 | } |
| 41 | |
| 42 | public function getText(LanguageAndRegion $language): ?string |
| 43 | { |
| 44 | return $this->translations[$language->toNative()] ?? null; |
| 45 | } |
| 46 | } |