Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| CompositeValueObjectStrategy | |
100.00% |
11 / 11 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMetadata | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| getCreationMetadata | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getModificationMetadata | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getResultMetadata | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Metadata\Strategy; |
| 3 | |
| 4 | use Apie\Core\Context\ApieContext; |
| 5 | use Apie\Core\Context\MetadataFieldHashmap; |
| 6 | use Apie\Core\Metadata\CompositeMetadata; |
| 7 | use Apie\Core\Metadata\Fields\PublicProperty; |
| 8 | use Apie\Core\Metadata\StrategyInterface; |
| 9 | use Apie\Core\Utils\ValueObjectUtils; |
| 10 | use Apie\Core\ValueObjects\Interfaces\ValueObjectInterface; |
| 11 | use ReflectionClass; |
| 12 | |
| 13 | final class CompositeValueObjectStrategy implements StrategyInterface |
| 14 | { |
| 15 | public static function supports(ReflectionClass $class): bool |
| 16 | { |
| 17 | return ValueObjectUtils::isCompositeValueObject($class); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * @param ReflectionClass<ValueObjectInterface> $class |
| 22 | */ |
| 23 | public function __construct(private ReflectionClass $class) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | private function getMetadata(ApieContext $context, bool $setterHooks): CompositeMetadata |
| 28 | { |
| 29 | $method = $this->class->getMethod('getFields'); |
| 30 | $map = []; |
| 31 | foreach ($method->invoke(null) as $name => $field) { |
| 32 | $prop = $this->class->getProperty($name); |
| 33 | $map[$name] = new PublicProperty($prop, $field->isOptional(), $setterHooks); |
| 34 | } |
| 35 | return new CompositeMetadata(new MetadataFieldHashmap($map), $this->class); |
| 36 | } |
| 37 | |
| 38 | public function getCreationMetadata(ApieContext $context): CompositeMetadata |
| 39 | { |
| 40 | return $this->getMetadata($context, true); |
| 41 | } |
| 42 | |
| 43 | public function getModificationMetadata(ApieContext $context): CompositeMetadata |
| 44 | { |
| 45 | return $this->getMetadata($context, true); |
| 46 | } |
| 47 | |
| 48 | public function getResultMetadata(ApieContext $context): CompositeMetadata |
| 49 | { |
| 50 | return $this->getMetadata($context, false); |
| 51 | } |
| 52 | } |