Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
10 / 11 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ItemListMetadata | |
90.91% |
10 / 11 |
|
83.33% |
5 / 6 |
7.04 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toClass | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| 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\ItemList; |
| 8 | use Apie\Core\Lists\StringList; |
| 9 | use Apie\Core\Metadata\Concerns\NoValueOptions; |
| 10 | use ReflectionClass; |
| 11 | |
| 12 | final class ItemListMetadata implements MetadataInterface |
| 13 | { |
| 14 | use NoValueOptions; |
| 15 | |
| 16 | /** |
| 17 | * @param ReflectionClass<ItemList> $class |
| 18 | */ |
| 19 | public function __construct(private readonly ReflectionClass $class, private readonly bool $creation = true) |
| 20 | { |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @return ReflectionClass<ItemList> |
| 25 | */ |
| 26 | public function toClass(): ReflectionClass |
| 27 | { |
| 28 | return $this->class; |
| 29 | } |
| 30 | |
| 31 | public function getHashmap(): MetadataFieldHashmap |
| 32 | { |
| 33 | return new MetadataFieldHashmap(); |
| 34 | } |
| 35 | |
| 36 | public function getRequiredFields(): StringList |
| 37 | { |
| 38 | return new StringList([]); |
| 39 | } |
| 40 | public function toScalarType(): ScalarType |
| 41 | { |
| 42 | return ScalarType::ARRAY; |
| 43 | } |
| 44 | public function getArrayItemType(): MetadataInterface |
| 45 | { |
| 46 | $strategy = MetadataFactory::getMetadataStrategyForType( |
| 47 | $this->class->getMethod('offsetGet')->getReturnType() |
| 48 | ); |
| 49 | return $this->creation |
| 50 | ? $strategy->getCreationMetadata(new ApieContext()) |
| 51 | : $strategy->getResultMetadata(new ApieContext()); |
| 52 | } |
| 53 | } |