Conditions | 6 |
Paths | 8 |
Total Lines | 25 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 6 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7401 | 17 | public static function str_replace_beginning( |
|
7402 | string $str, |
||
7403 | string $search, |
||
7404 | string $replacement |
||
7405 | ): string { |
||
7406 | 17 | if ($str === '') { |
|
7407 | 4 | if ($replacement === '') { |
|
7408 | 2 | return ''; |
|
7409 | } |
||
7410 | |||
7411 | 2 | if ($search === '') { |
|
7412 | 2 | return $replacement; |
|
7413 | } |
||
7414 | } |
||
7415 | |||
7416 | 13 | if ($search === '') { |
|
7417 | 2 | return $str . $replacement; |
|
7418 | } |
||
7419 | |||
7420 | 11 | $searchLength = \strlen($search); |
|
7421 | 11 | if (\strncmp($str, $search, $searchLength) === 0) { |
|
7422 | 9 | return $replacement . \substr($str, $searchLength); |
|
7423 | } |
||
7424 | |||
7425 | 2 | return $str; |
|
7426 | } |
||
13722 |