Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
64.29% covered (warning)
64.29%
9 / 14
75.00% covered (warning)
75.00%
6 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
ValueObjectMetadata
64.29% covered (warning)
64.29%
9 / 14
75.00% covered (warning)
75.00%
6 / 8
14.56
0.00% covered (danger)
0.00%
0 / 1
 getValueOptions
33.33% covered (danger)
33.33%
2 / 6
0.00% covered (danger)
0.00%
0 / 1
5.67
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toClass
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNativeType
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getHashmap
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRequiredFields
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 toScalarType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getArrayItemType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Core\Metadata;
3
4use Apie\Core\Context\ApieContext;
5use Apie\Core\Context\MetadataFieldHashmap;
6use Apie\Core\Dto\ValueOption;
7use Apie\Core\Enums\ScalarType;
8use Apie\Core\Lists\StringList;
9use Apie\Core\Lists\ValueOptionList;
10use Apie\Core\ValueObjects\Interfaces\LimitedOptionsInterface;
11use Apie\Core\ValueObjects\Interfaces\ValueObjectInterface;
12use Apie\Core\ValueObjects\Utils;
13use ReflectionClass;
14
15class ValueObjectMetadata implements NullableMetadataInterface
16{
17    // TODO: check regex to see if the options are limited?
18    public function getValueOptions(ApieContext $context, bool $runtimeFilter = false): ?ValueOptionList
19    {
20        if (in_array(LimitedOptionsInterface::class, $this->class->getInterfaceNames())) {
21            //$translator = $context->getContext(ApieTranslator::class, false) ? : new ApieTranslator();
22            $options = [];
23            foreach ($this->class->getMethod('getOptions')->invoke(null) as $option) {
24                $options[] = new ValueOption(Utils::toString($option), $option);
25            }
26            return new ValueOptionList($options);
27        }
28        return null;
29    }
30    /**
31     * @param ReflectionClass<ValueObjectInterface> $class
32     */
33    public function __construct(private ReflectionClass $class)
34    {
35    }
36
37    /**
38     * @return ReflectionClass<ValueObjectInterface>
39     */
40    public function toClass(): ReflectionClass
41    {
42        return $this->class;
43    }
44
45    public function getNativeType(): MetadataInterface
46    {
47        $method = $this->class->getMethod('toNative');
48        return MetadataFactory::getCreationMetadata($method->getReturnType(), new ApieContext());
49    }
50
51    public function getHashmap(): MetadataFieldHashmap
52    {
53        return $this->getNativeType()->getHashmap();
54    }
55
56    public function getRequiredFields(): StringList
57    {
58        return $this->getNativeType()->getRequiredFields();
59    }
60
61    public function toScalarType(bool $ignoreNull = false): ScalarType
62    {
63        return $this->getNativeType()->toScalarType($ignoreNull);
64    }
65
66    public function getArrayItemType(): ?MetadataInterface
67    {
68        return $this->getNativeType()->getArrayItemType();
69    }
70}