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 | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| TextConfig | 83.33% | 5 / 6 | 50.00% | 1 / 2 | 6.17 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 5 | |||||
| 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 | ||
| 9 | final readonly class TextConfig extends ExposedEntityConfig | |
| 10 | { | |
| 11 | public const int MAX_LENGTH = 255; | |
| 12 | ||
| 13 | /** @throws ExposureException */ | |
| 14 | public function __construct( | |
| 15 | public int $min = 0, | |
| 16 | public int $max = self::MAX_LENGTH, | |
| 17 | public ?string $pattern = null, | |
| 18 | public TextMode $mode = TextMode::Text, | |
| 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 ($min < 0 || $min > $max || $max > self::MAX_LENGTH) { | |
| 27 | throw ExposureException::configInvalid(\sprintf('The text length limits must satisfy 0 <= min <= max <= %d.', self::MAX_LENGTH)); | |
| 28 | } | |
| 29 | ||
| 30 | if ($pattern === '') { | |
| 31 | throw ExposureException::configInvalid('The text pattern must not be empty; leave it null for none.'); | |
| 32 | } | |
| 33 | } | |
| 34 | ||
| 35 | public function getPlatform(): ExposedPlatform | |
| 36 | { | |
| 37 | return ExposedPlatform::Text; | |
| 38 | } | |
| 39 | } |