Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Envelope | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| format | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
| isStructured | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Richtext; |
| 6 | |
| 7 | /** |
| 8 | * The format envelope of stored richtext values. In node content the |
| 9 | * envelope keys (`format`, `version`) live on the field or block |
| 10 | * object next to `value`; a missing `format` marks legacy HTML from |
| 11 | * before the structured-richtext migration. |
| 12 | */ |
| 13 | final class Envelope |
| 14 | { |
| 15 | public const string FORMAT = 'cosray-richtext'; |
| 16 | public const string HTML = 'html'; |
| 17 | public const int VERSION = 1; |
| 18 | |
| 19 | /** @param array<string, mixed> $data A field or block data array. */ |
| 20 | public static function format(array $data): string |
| 21 | { |
| 22 | $format = $data['format'] ?? null; |
| 23 | |
| 24 | return is_string($format) && $format !== '' ? $format : self::HTML; |
| 25 | } |
| 26 | |
| 27 | /** @param array<string, mixed> $data A field or block data array. */ |
| 28 | public static function isStructured(array $data): bool |
| 29 | { |
| 30 | return self::format($data) === self::FORMAT; |
| 31 | } |
| 32 | } |