Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
84.62% |
11 / 13 |
|
75.00% |
6 / 8 |
CRAP | |
0.00% |
0 / 1 |
| CustomObjectsMetadata | |
84.62% |
11 / 13 |
|
75.00% |
6 / 8 |
9.29 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| getDisplayName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getHashmap | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRequiredFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toScalarType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getArrayItemType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getValueOptions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toClass | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Metadata; |
| 3 | |
| 4 | use Apie\Core\Context\ApieContext; |
| 5 | use Apie\Core\Context\MetadataFieldHashmap; |
| 6 | use Apie\Core\Enums\ScalarType; |
| 7 | use Apie\Core\Lists\StringList; |
| 8 | use Apie\Core\Lists\ValueOptionList; |
| 9 | use Apie\TypeConverter\ReflectionTypeFactory; |
| 10 | use BcMath\Number; |
| 11 | use GMP; |
| 12 | use ReflectionClass; |
| 13 | use Uri\Rfc3986\Uri; |
| 14 | |
| 15 | class CustomObjectsMetadata implements MetadataInterface |
| 16 | { |
| 17 | /** |
| 18 | * @var array<class-string<covariant object>, string> $mapping |
| 19 | */ |
| 20 | private static array $mapping = [ |
| 21 | Uri::class => 'string', |
| 22 | Number::class => 'string', |
| 23 | GMP::class => 'string', |
| 24 | ]; |
| 25 | |
| 26 | private MetadataInterface $internal; |
| 27 | |
| 28 | /** |
| 29 | * @param ReflectionClass<covariant object> $class |
| 30 | */ |
| 31 | public function __construct(private readonly ReflectionClass $class) |
| 32 | { |
| 33 | $this->internal = new ScalarMetadata(ScalarType::MIXED); |
| 34 | if (isset(self::$mapping[$class->name])) { |
| 35 | $strategy = MetadataFactory::getMetadataStrategyForType( |
| 36 | ReflectionTypeFactory::createReflectionType(self::$mapping[$class->name]) |
| 37 | ); |
| 38 | $this->internal = $strategy->getResultMetadata(new ApieContext()); |
| 39 | } |
| 40 | } |
| 41 | public function getDisplayName(): string |
| 42 | { |
| 43 | return $this->class->getShortName(); |
| 44 | } |
| 45 | public function getHashmap(): MetadataFieldHashmap |
| 46 | { |
| 47 | return new MetadataFieldHashmap(); |
| 48 | } |
| 49 | public function getRequiredFields(): StringList |
| 50 | { |
| 51 | return new StringList(); |
| 52 | } |
| 53 | public function toScalarType(): ScalarType |
| 54 | { |
| 55 | return $this->internal->toScalarType(); |
| 56 | } |
| 57 | public function getArrayItemType(): ?MetadataInterface |
| 58 | { |
| 59 | return null; |
| 60 | } |
| 61 | public function getValueOptions(ApieContext $context, bool $runtimeFilter = false): ?ValueOptionList |
| 62 | { |
| 63 | return $this->internal->getValueOptions($context, $runtimeFilter); |
| 64 | } |
| 65 | public function toClass(): ?ReflectionClass |
| 66 | { |
| 67 | return $this->class; |
| 68 | } |
| 69 | } |