@@ -7,31 +7,38 @@ final class StringNormalizer
77
88 /**
99 * @var string[]
10- * @copyright https://stackoverflow.com/a/12824140
1110 */
1211 private static array $ emojiRegexes = [
13- '\x{1F600}-\x{1F64F} ' , // emoticons,
14- '\x{1F300}-\x{1F5FF} ' , // miscellaneous, pictographs
15- '\x{1F680}-\x{1F6FF} ' , // transport, map symbols
16- '\x{2600}-\x{26FF} ' , // miscellaneous
17- '\x{2700}-\x{27BF} ' , // dingbats
12+ // emoticons,
13+ '\x{1F600}-\x{1F64F} ' ,
14+ // miscellaneous, pictographs
15+ '\x{1F300}-\x{1F5FF} ' ,
16+ // transport, map symbols
17+ '\x{1F680}-\x{1F6FF} ' ,
18+ // miscellaneous
19+ '\x{2600}-\x{26FF} ' ,
20+ // dingbats
21+ '\x{2700}-\x{27BF} ' ,
1822 ];
1923
2024 public static function normalizeSpaces (string $ str ): string
2125 {
22- return preg_replace ('# {2,}# ' , ' ' , trim ($ str ));
26+ return ( string ) preg_replace ('# {2,}# ' , ' ' , trim ($ str ));
2327 }
2428
2529 public static function normalizeWhitespaces (string $ str ): string
2630 {
27- $ str = preg_replace ('#[\r\n]+# ' , ' ' , trim ($ str ));
31+ $ str = ( string ) preg_replace ('#[\r\n]+# ' , ' ' , trim ($ str ));
2832
29- return preg_replace ('#\s{2,}# ' , ' ' , $ str );
33+ return ( string ) preg_replace ('#\s{2,}# ' , ' ' , $ str );
3034 }
3135
3236 public static function normalizeEmoji (string $ str ): string
3337 {
34- return trim (preg_replace (sprintf ('#\s*[%s]+\s*#u ' , implode ('' , self ::$ emojiRegexes )), ' ' , $ str ), ' ' );
38+ return (string ) trim (
39+ (string ) preg_replace (sprintf ('#\s*[%s]+\s*#u ' , implode ('' , self ::$ emojiRegexes )), ' ' , $ str ),
40+ ' '
41+ );
3542 }
3643
3744}
0 commit comments