Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
CompositeMetadata
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
6 / 6
10
100.00% covered (success)
100.00%
1 / 1
 __construct
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
 toScalarType
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
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
5
 getArrayItemType
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\MetadataFieldHashmap;
5use Apie\Core\Enums\ScalarType;
6use Apie\Core\Lists\StringList;
7use Apie\Core\Metadata\Concerns\NoValueOptions;
8use Apie\Core\ValueObjects\Interfaces\ValueObjectInterface;
9use ReflectionClass;
10
11/**
12 * Composite value objects
13 * - Implements ValueObjectInterface
14 * - has CompositeValueObject trait
15 * - is always mapped as an object
16 */
17final class CompositeMetadata implements MetadataInterface
18{
19    use NoValueOptions;
20
21    private ?StringList $requiredFields = null;
22
23    /**
24     * @param ReflectionClass<ValueObjectInterface> $class
25     */
26    public function __construct(private readonly MetadataFieldHashmap $hashmap, private ?ReflectionClass $class = null)
27    {
28    }
29
30    /**
31     * @return ReflectionClass<ValueObjectInterface>
32     */
33    public function toClass(): ?ReflectionClass
34    {
35        return $this->class;
36    }
37
38    public function toScalarType(): ScalarType
39    {
40        return ScalarType::STDCLASS;
41    }
42
43    public function getHashmap(): MetadataFieldHashmap
44    {
45        return $this->hashmap;
46    }
47
48    public function getRequiredFields(): StringList
49    {
50        if (null === $this->requiredFields) {
51            $required = [];
52            foreach ($this->hashmap as $name => $field) {
53                if ($field->isField() && $field->isRequired()) {
54                    $required[] = $name;
55                }
56            }
57            $this->requiredFields = new StringList($required);
58        }
59        return $this->requiredFields;
60    }
61
62    public function getArrayItemType(): ?MetadataInterface
63    {
64        return null;
65    }
66}