Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| TypesHandler | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| resolve | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Collection\Schema; |
| 6 | |
| 7 | use Cosray\Exception\RuntimeException; |
| 8 | use Cosray\Schema\Types; |
| 9 | use Override; |
| 10 | |
| 11 | class TypesHandler extends Handler |
| 12 | { |
| 13 | #[Override] |
| 14 | public function resolve(object $meta, string $class): array |
| 15 | { |
| 16 | assert($meta instanceof Types, 'The registry maps #[Types] to this handler'); |
| 17 | |
| 18 | $types = array_map(trim(...), $meta->types); |
| 19 | |
| 20 | if ($types === [] || in_array('', $types, true)) { |
| 21 | throw new RuntimeException("#[Types] of collection '{$class}' must name at least one node type"); |
| 22 | } |
| 23 | |
| 24 | return ['types' => $types]; |
| 25 | } |
| 26 | } |