Lines
83.33%
5 / 6
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| SelectConfig | 83.33% | 5 / 6 | 50.00% | 1 / 2 | 5.12 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 4 | |||||
| getPlatform | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Contracts\Exposure; | |
| 6 | ||
| 7 | use Stewart\Contracts\Exception\ExposureException; | |
| 8 | use Stewart\Contracts\Wire\ListOf; | |
| 9 | ||
| 10 | final readonly class SelectConfig extends ExposedEntityConfig | |
| 11 | { | |
| 12 | /** | |
| 13 | * @param list<string> $options | |
| 14 | * @throws ExposureException | |
| 15 | */ | |
| 16 | public function __construct( | |
| 17 | #[ListOf('string')] | |
| 18 | public array $options, | |
| 19 | ?string $name = null, | |
| 20 | ?string $icon = null, | |
| 21 | ?EntityCategory $entityCategory = null, | |
| 22 | bool $enabledByDefault = true, | |
| 23 | ) { | |
| 24 | parent::__construct($name, $icon, $entityCategory, $enabledByDefault); | |
| 25 | ||
| 26 | if ($options === []) { | |
| 27 | throw ExposureException::configInvalid('A select needs at least one option.'); | |
| 28 | } | |
| 29 | ||
| 30 | if (\in_array('', $options, true) || \count(array_unique($options)) !== \count($options)) { | |
| 31 | throw ExposureException::configInvalid('The select options must be distinct and not empty.'); | |
| 32 | } | |
| 33 | } | |
| 34 | ||
| 35 | public function getPlatform(): ExposedPlatform | |
| 36 | { | |
| 37 | return ExposedPlatform::Select; | |
| 38 | } | |
| 39 | } |