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\Core\Other\StreamBucketObject; |
| 10 | use Apie\Core\ValueObjects\PhpDateIntervalString; |
| 11 | use Apie\TypeConverter\ReflectionTypeFactory; |
| 12 | use BcMath\Number; |
| 13 | use DateInterval; |
| 14 | use DOMAttr; |
| 15 | use DOMElement; |
| 16 | use FFI\CType; |
| 17 | use GMP; |
| 18 | use ReflectionClass; |
| 19 | use SimpleXMLElement; |
| 20 | use StreamBucket; |
| 21 | use Uri\Rfc3986\Uri; |
| 22 | |
| 23 | class CustomObjectsMetadata implements MetadataInterface |
| 24 | { |
| 25 | /** |
| 26 | * @var array<class-string<covariant object>, string> $mapping |
| 27 | */ |
| 28 | private static array $mapping = [ |
| 29 | Uri::class => 'string', |
| 30 | Number::class => 'string', |
| 31 | GMP::class => 'string', |
| 32 | StreamBucket::class => StreamBucketObject::class, |
| 33 | CType::class => 'string|int|float|null|' . StringList::class, |
| 34 | SimpleXMLElement::class => 'string', |
| 35 | DOMAttr::class => 'string', |
| 36 | DOMElement::class => 'string', |
| 37 | DateInterval::class => PhpDateIntervalString::class, |
| 38 | ]; |
| 39 | |
| 40 | private MetadataInterface $internal; |
| 41 | |
| 42 | /** |
| 43 | * @param ReflectionClass<covariant object> $class |
| 44 | */ |
| 45 | public function __construct(private readonly ReflectionClass $class) |
| 46 | { |
| 47 | $this->internal = new ScalarMetadata(ScalarType::MIXED); |
| 48 | if (isset(self::$mapping[$class->name])) { |
| 49 | $strategy = MetadataFactory::getMetadataStrategyForType( |
| 50 | ReflectionTypeFactory::createReflectionType(self::$mapping[$class->name]) |
| 51 | ); |
| 52 | $this->internal = $strategy->getResultMetadata(new ApieContext()); |
| 53 | } |
| 54 | } |
| 55 | public function getDisplayName(): string |
| 56 | { |
| 57 | return $this->class->getShortName(); |
| 58 | } |
| 59 | public function getHashmap(): MetadataFieldHashmap |
| 60 | { |
| 61 | return new MetadataFieldHashmap(); |
| 62 | } |
| 63 | public function getRequiredFields(): StringList |
| 64 | { |
| 65 | return new StringList(); |
| 66 | } |
| 67 | public function toScalarType(): ScalarType |
| 68 | { |
| 69 | return $this->internal->toScalarType(); |
| 70 | } |
| 71 | public function getArrayItemType(): ?MetadataInterface |
| 72 | { |
| 73 | return null; |
| 74 | } |
| 75 | public function getValueOptions(ApieContext $context, bool $runtimeFilter = false): ?ValueOptionList |
| 76 | { |
| 77 | return $this->internal->getValueOptions($context, $runtimeFilter); |
| 78 | } |
| 79 | public function toClass(): ?ReflectionClass |
| 80 | { |
| 81 | return $this->class; |
| 82 | } |
| 83 | } |