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