Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
84.21% covered (warning)
84.21%
16 / 19
62.50% covered (warning)
62.50%
5 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
ScalarMetadata
84.21% covered (warning)
84.21%
16 / 19
62.50% covered (warning)
62.50%
5 / 8
12.57
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
 getDisplayName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 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 getDisplayName(): string
19    {
20        return $this->type->name;
21    }
22
23    public function getValueOptions(ApieContext $context, bool $runtimeFilter = false): ?ValueOptionList
24    {
25        if ($this->type === ScalarType::BOOLEAN) {
26            return new ValueOptionList([
27                new ValueOption('True', true),
28                new ValueOption('False', false),
29            ]);
30        }
31        if ($this->type === ScalarType::NULLVALUE) {
32            return new ValueOptionList([
33                new ValueOption('(null)', null)
34            ]);
35        }
36        return null;
37    }
38
39    public function toClass(): ?ReflectionClass
40    {
41        return null;
42    }
43
44    public function getHashmap(): MetadataFieldHashmap
45    {
46        return new MetadataFieldHashmap();
47    }
48
49    public function getRequiredFields(): StringList
50    {
51        return new StringList([]);
52    }
53
54    public function toScalarType(): ScalarType
55    {
56        return $this->type;
57    }
58
59    public function getArrayItemType(): ?MetadataInterface
60    {
61        if ($this->type === ScalarType::ARRAY || $this->type === ScalarType::STDCLASS) {
62            return new ScalarMetadata(ScalarType::MIXED);
63        }
64        return null;
65    }
66}