Lines
100.00%
10 / 10
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| from | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 4 | ||
| 10 | final readonly class DelimitedMessage implements Message | |
| 11 | { | |
| 12 | /** @param non-empty-list<string> $data */ | |
| 13 | public function __construct( | |
| 14 | public array $data, | |
| 15 | public string $raw, | |
| 16 | ) {} | |
| 17 | ||
| 18 | /** @return Option\Option<static> */ | |
| 19 | #[Override] | |
| 20 | public static function from(string $message): Option\Option | |
| 21 | { | |
| 22 | if (!str_starts_with($message, '%') || !str_ends_with($message, '%')) { | |
| 23 | return Option\none(); | |
| 24 | } | |
| 25 | ||
| 26 | $segments = array_values(array_filter( | |
| 27 | explode('%', $message), | |
| 28 | static fn(string $segment): bool => $segment !== '', | |
| 29 | )); | |
| 30 | ||
| 31 | if ($segments === []) { | |
| 32 | return Option\none(); | |
| 33 | } | |
| 34 | ||
| 35 | return Option\some(new self($segments, $message)); | |
| 36 | } | |
| 37 | } |