Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
84.62% covered (warning)
84.62%
11 / 13
75.00% covered (warning)
75.00%
6 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
CustomObjectsMetadata
84.62% covered (warning)
84.62%
11 / 13
75.00% covered (warning)
75.00%
6 / 8
9.29
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 getDisplayName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 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
 getValueOptions
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
1<?php
2namespace Apie\Core\Metadata;
3
4use Apie\Core\Context\ApieContext;
5use Apie\Core\Context\MetadataFieldHashmap;
6use Apie\Core\Enums\ScalarType;
7use Apie\Core\Lists\StringList;
8use Apie\Core\Lists\ValueOptionList;
9use Apie\Core\Other\StreamBucketObject;
10use Apie\Core\ValueObjects\PhpDateIntervalString;
11use Apie\TypeConverter\ReflectionTypeFactory;
12use BcMath\Number;
13use DateInterval;
14use DOMAttr;
15use DOMElement;
16use FFI\CType;
17use GMP;
18use ReflectionClass;
19use SimpleXMLElement;
20use StreamBucket;
21use Uri\Rfc3986\Uri;
22
23class 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}