Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ProcessPlainText | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
4.02 | |
0.00% |
0 / 1 |
| normalize | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| charLength | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsentities\Helper; |
| 4 | |
| 5 | /** |
| 6 | * Plain-text normalization for process amendment and custom text fields. |
| 7 | */ |
| 8 | class ProcessPlainText |
| 9 | { |
| 10 | public const MAX_CUSTOM_TEXTFIELD_CHARS = 250; |
| 11 | |
| 12 | public const MAX_AMENDMENT_CHARS = 500; |
| 13 | |
| 14 | /** |
| 15 | * Strip HTML, decode entities, normalize line breaks to "\n" for storage/display. |
| 16 | */ |
| 17 | public static function normalize(?string $input): string |
| 18 | { |
| 19 | if ($input === null || $input === '') { |
| 20 | return ''; |
| 21 | } |
| 22 | $s = (string) $input; |
| 23 | $s = html_entity_decode($s, ENT_QUOTES | ENT_HTML5, 'UTF-8'); |
| 24 | $s = str_replace(["\r\n", "\r"], "\n", $s); |
| 25 | $s = preg_replace('/<\s*br\s*\/?>/iu', "\n", $s) ?? $s; |
| 26 | $s = strip_tags($s); |
| 27 | |
| 28 | return $s; |
| 29 | } |
| 30 | |
| 31 | public static function charLength(?string $input): int |
| 32 | { |
| 33 | return mb_strlen(self::normalize($input), 'UTF-8'); |
| 34 | } |
| 35 | } |