Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
StorageMappingAttributeConverter
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 applyToDomain
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 applyToStorage
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2namespace Apie\StorageMetadata\PropertyConverters;
3
4use Apie\Core\FileStorage\StoredFile;
5use Apie\StorageMetadata\Attributes\StorageMappingAttribute;
6use Apie\StorageMetadata\Interfaces\PropertyConverterInterface;
7use Apie\StorageMetadata\Mediators\DomainToStorageContext;
8use ReflectionProperty;
9
10class 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}