Conditions | 5 |
Paths | 5 |
Total Lines | 22 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 5.0144 |
Changes | 6 | ||
Bugs | 4 | Features | 0 |
1 | <?php |
||
5031 | 54 | public static function remove_bom(string $str): string |
|
5032 | { |
||
5033 | 54 | if ($str === '') { |
|
5034 | 9 | return ''; |
|
5035 | } |
||
5036 | |||
5037 | 54 | $str_length = \strlen($str); |
|
5038 | 54 | foreach (self::$BOM as $bom_string => $bom_byte_length) { |
|
5039 | 54 | if (\strncmp($str, $bom_string, $bom_byte_length) === 0) { |
|
5040 | /** @var false|string $str_tmp - needed for PhpStan (stubs error) */ |
||
5041 | 9 | $str_tmp = \substr($str, $bom_byte_length, $str_length); |
|
5042 | 9 | if ($str_tmp === false) { |
|
5043 | return ''; |
||
5044 | } |
||
5045 | |||
5046 | 9 | $str_length -= $bom_byte_length; |
|
5047 | |||
5048 | 54 | $str = (string) $str_tmp; |
|
5049 | } |
||
5050 | } |
||
5051 | |||
5052 | 54 | return $str; |
|
5053 | } |
||
13693 |