Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.89% covered (warning)
88.89%
16 / 18
71.43% covered (warning)
71.43%
5 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
ScalarMetadata
88.89% covered (warning)
88.89%
16 / 18
71.43% covered (warning)
71.43%
5 / 7
11.17
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getValueOptions
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
3
 toClass
100.00% covered (success)
100.00%
1 / 1
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
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
3.33
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 ReflectionClass;
11
12final class ScalarMetadata implements MetadataInterface
13{
14    public function __construct(private ScalarType $type)
15    {
16    }
17
18    public function getValueOptions(ApieContext $context, bool $runtimeFilter = false): ?ValueOptionList
19    {
20        if ($this->type === ScalarType::BOOLEAN) {
21            return new ValueOptionList([
22                new ValueOption('True', true),
23                new ValueOption('False', false),
24            ]);
25        }
26        if ($this->type === ScalarType::NULLVALUE) {
27            return new ValueOptionList([
28                new ValueOption('(null)', null)
29            ]);
30        }
31        return null;
32    }
33
34    public function toClass(): ?ReflectionClass
35    {
36        return null;
37    }
38
39    public function getHashmap(): MetadataFieldHashmap
40    {
41        return new MetadataFieldHashmap();
42    }
43
44    public function getRequiredFields(): StringList
45    {
46        return new StringList([]);
47    }
48
49    public function toScalarType(): ScalarType
50    {
51        return $this->type;
52    }
53
54    public function getArrayItemType(): ?MetadataInterface
55    {
56        if ($this->type === ScalarType::ARRAY || $this->type === ScalarType::STDCLASS) {
57            return new ScalarMetadata(ScalarType::MIXED);
58        }
59        return null;
60    }
61}