Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Children | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Schema; |
| 6 | |
| 7 | use Attribute; |
| 8 | use Cosray\Exception\RuntimeException; |
| 9 | |
| 10 | /** |
| 11 | * The node types allowed as direct children. `sortable` gives the children |
| 12 | * a manual order: editors arrange them in the panel, and `children()` |
| 13 | * returns them in that order. |
| 14 | */ |
| 15 | #[Attribute(Attribute::TARGET_CLASS)] |
| 16 | readonly class Children |
| 17 | { |
| 18 | /** @var list<class-string> */ |
| 19 | public array $types; |
| 20 | |
| 21 | /** @param class-string|list<class-string> $types */ |
| 22 | public function __construct( |
| 23 | string|array $types, |
| 24 | public bool $sortable = false, |
| 25 | ) { |
| 26 | $types = is_string($types) ? [$types] : array_values($types); |
| 27 | |
| 28 | foreach ($types as $type) { |
| 29 | if (!is_string($type) || trim($type) === '') { |
| 30 | throw new RuntimeException('#[Children] needs non-empty class names'); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | $this->types = $types; |
| 35 | } |
| 36 | } |