Conditions | 6 |
Paths | 7 |
Total Lines | 33 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 6.7717 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8799 | 2 | public static function str_substr_first( |
|
8800 | string $str, |
||
8801 | string $needle, |
||
8802 | bool $before_needle = false, |
||
8803 | string $encoding = 'UTF-8' |
||
8804 | ): string { |
||
8805 | 2 | if ($str === '' || $needle === '') { |
|
8806 | 2 | return ''; |
|
8807 | } |
||
8808 | |||
8809 | 2 | if ($encoding === 'UTF-8') { |
|
8810 | 2 | if ($before_needle) { |
|
8811 | 1 | $part = \mb_strstr( |
|
8812 | 1 | $str, |
|
8813 | 1 | $needle, |
|
8814 | 1 | $before_needle |
|
8815 | ); |
||
8816 | } else { |
||
8817 | 1 | $part = \mb_strstr( |
|
8818 | 1 | $str, |
|
8819 | 2 | $needle |
|
8820 | ); |
||
8821 | } |
||
8822 | } else { |
||
8823 | $part = self::strstr( |
||
8824 | $str, |
||
8825 | $needle, |
||
8826 | $before_needle, |
||
8827 | $encoding |
||
8828 | ); |
||
8829 | } |
||
8830 | |||
8831 | 2 | return $part === false ? '' : $part; |
|
8832 | } |
||
14792 |