Conditions | 6 |
Paths | 5 |
Total Lines | 31 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 8.048 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8209 | 1 | public static function str_substr_before_last_separator(string $str, string $separator, string $encoding = 'UTF-8'): string |
|
8210 | { |
||
8211 | 1 | if ($separator === '' || $str === '') { |
|
8212 | 1 | return ''; |
|
8213 | } |
||
8214 | |||
8215 | 1 | if ($encoding === 'UTF-8') { |
|
8216 | 1 | $offset = \mb_strrpos($str, $separator); |
|
8217 | 1 | if ($offset === false) { |
|
8218 | 1 | return ''; |
|
8219 | } |
||
8220 | |||
8221 | 1 | return (string) \mb_substr( |
|
8222 | $str, |
||
8223 | 0, |
||
8224 | $offset |
||
8225 | ); |
||
8226 | } |
||
8227 | |||
8228 | $offset = self::strrpos($str, $separator, 0, $encoding); |
||
8229 | if ($offset === false) { |
||
8230 | return ''; |
||
8231 | } |
||
8232 | |||
8233 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
||
8234 | |||
8235 | return (string) self::substr( |
||
8236 | $str, |
||
8237 | 0, |
||
8238 | $offset, |
||
8239 | $encoding |
||
8240 | ); |
||
13722 |