Conditions | 8 |
Paths | 8 |
Total Lines | 33 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 14.2906 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
6095 | public static function str_delimit( |
||
6096 | string $str, |
||
6097 | string $delimiter, |
||
6098 | string $encoding = 'UTF-8', |
||
6099 | bool $clean_utf8 = false, |
||
6100 | string $lang = null, |
||
6101 | bool $try_to_keep_the_string_length = false |
||
6102 | ): string { |
||
6103 | 49 | if (self::$SUPPORT['mbstring'] === true) { |
|
6104 | /** @noinspection PhpComposerExtensionStubsInspection */ |
||
6105 | 49 | $str = (string) \mb_ereg_replace('\\B(\\p{Lu})', '-\1', \trim($str)); |
|
6106 | |||
6107 | 49 | $use_mb_functions = $lang === null && !$try_to_keep_the_string_length; |
|
6108 | 49 | if ($use_mb_functions && $encoding === 'UTF-8') { |
|
6109 | 22 | $str = \mb_strtolower($str); |
|
6110 | } else { |
||
6111 | 27 | $str = self::strtolower($str, $encoding, $clean_utf8, $lang, $try_to_keep_the_string_length); |
|
6112 | } |
||
6113 | |||
6114 | /** @noinspection PhpComposerExtensionStubsInspection */ |
||
6115 | 49 | return (string) \mb_ereg_replace('[\\-_\\s]+', $delimiter, $str); |
|
6116 | } |
||
6117 | |||
6118 | $str = (string) \preg_replace('/\\B(\\p{Lu})/u', '-\1', \trim($str)); |
||
6119 | |||
6120 | $use_mb_functions = $lang === null && !$try_to_keep_the_string_length; |
||
6121 | if ($use_mb_functions && $encoding === 'UTF-8') { |
||
6122 | $str = \mb_strtolower($str); |
||
6123 | } else { |
||
6124 | $str = self::strtolower($str, $encoding, $clean_utf8, $lang, $try_to_keep_the_string_length); |
||
6125 | } |
||
6126 | |||
6127 | return (string) \preg_replace('/[\\-_\\s]+/u', $delimiter, $str); |
||
6128 | } |
||
14578 |