Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DiscriminatorMappingAttributeConverter
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 applyToDomain
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 applyToStorage
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2namespace Apie\StorageMetadata\PropertyConverters;
3
4use Apie\Core\Entities\PolymorphicEntityInterface;
5use Apie\Core\Utils\EntityUtils;
6use Apie\StorageMetadata\Attributes\DiscriminatorMappingAttribute;
7use Apie\StorageMetadata\Interfaces\PropertyConverterInterface;
8use Apie\StorageMetadata\Mediators\DomainToStorageContext;
9
10class DiscriminatorMappingAttributeConverter implements PropertyConverterInterface
11{
12    public function applyToDomain(
13        DomainToStorageContext $context
14    ): void {
15        // no-op
16    }
17
18    public function applyToStorage(
19        DomainToStorageContext $context
20    ): void {
21        if ($context->domainObject instanceof PolymorphicEntityInterface) {
22            $mapping = EntityUtils::getDiscriminatorValues($context->domainObject, $context->domainClass);
23            foreach ($context->storageProperty->getAttributes(DiscriminatorMappingAttribute::class) as $propertyAttribute) {
24                $context->setStoragePropertyValue($mapping);
25            }
26        }
27    }
28}