Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
83.33% |
5 / 6 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DefaultValueAttributeConverter | |
83.33% |
5 / 6 |
|
50.00% |
1 / 2 |
6.17 | |
0.00% |
0 / 1 |
| applyToDomain | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| applyToStorage | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
5.20 | |||
| 1 | <?php |
| 2 | namespace Apie\StorageMetadata\PropertyConverters; |
| 3 | |
| 4 | use Apie\StorageMetadata\Interfaces\PropertyConverterInterface; |
| 5 | use Apie\StorageMetadata\Mediators\DomainToStorageContext; |
| 6 | |
| 7 | class DefaultValueAttributeConverter implements PropertyConverterInterface |
| 8 | { |
| 9 | public function applyToDomain( |
| 10 | DomainToStorageContext $context |
| 11 | ): void { |
| 12 | } |
| 13 | |
| 14 | public function applyToStorage( |
| 15 | DomainToStorageContext $context |
| 16 | ): void { |
| 17 | if (!$context->storageProperty->isInitialized($context->storageObject)) { |
| 18 | if ($context->storageProperty->hasDefaultValue()) { |
| 19 | $context->storageProperty->setValue($context->storageObject, $context->storageProperty->getDefaultValue()); |
| 20 | } elseif (!$context->storageProperty->getType() || $context->storageProperty->getType()->allowsNull()) { |
| 21 | $context->storageProperty->setValue($context->storageObject, null); |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | } |