Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| StorageMappingAttributeConverter | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| applyToDomain | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| applyToStorage | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\StorageMetadata\PropertyConverters; |
| 3 | |
| 4 | use Apie\Core\FileStorage\StoredFile; |
| 5 | use Apie\StorageMetadata\Attributes\StorageMappingAttribute; |
| 6 | use Apie\StorageMetadata\Interfaces\PropertyConverterInterface; |
| 7 | use Apie\StorageMetadata\Mediators\DomainToStorageContext; |
| 8 | use ReflectionProperty; |
| 9 | |
| 10 | class StorageMappingAttributeConverter implements PropertyConverterInterface |
| 11 | { |
| 12 | public function applyToDomain( |
| 13 | DomainToStorageContext $context |
| 14 | ): void { |
| 15 | foreach ($context->storageProperty->getAttributes(StorageMappingAttribute::class) as $attribute) { |
| 16 | (new ReflectionProperty(StoredFile::class, 'storage'))->setValue( |
| 17 | $context->domainObject, |
| 18 | $context->fileStorage |
| 19 | ); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | public function applyToStorage( |
| 24 | DomainToStorageContext $context |
| 25 | ): void { |
| 26 | foreach ($context->storageProperty->getAttributes(StorageMappingAttribute::class) as $attribute) { |
| 27 | $context->storageProperty->setValue($context->storageObject, $context->fileStorage); |
| 28 | } |
| 29 | } |
| 30 | } |