Lines 88.88% 8 / 9
Methods 50.00% 1 / 2
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 normalize 100.00% 8 / 8 100.00% 1 / 1 3
 charLength 0.00% 0 / 1 0.00% 0 / 1 2
8class ProcessPlainText
9{
10    public const int MAX_CUSTOM_TEXTFIELD_CHARS = 250;
11
12    public const int 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 = $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}