Conditions | 6 |
Paths | 8 |
Total Lines | 24 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 6 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7394 | 17 | public static function str_replace_ending( |
|
7395 | string $str, |
||
7396 | string $search, |
||
7397 | string $replacement |
||
7398 | ): string { |
||
7399 | 17 | if ($str === '') { |
|
7400 | 4 | if ($replacement === '') { |
|
7401 | 2 | return ''; |
|
7402 | } |
||
7403 | |||
7404 | 2 | if ($search === '') { |
|
7405 | 2 | return $replacement; |
|
7406 | } |
||
7407 | } |
||
7408 | |||
7409 | 13 | if ($search === '') { |
|
7410 | 2 | return $str . $replacement; |
|
7411 | } |
||
7412 | |||
7413 | 11 | if (\strpos($str, $search, \strlen($str) - \strlen($search)) !== false) { |
|
7414 | 8 | $str = \substr($str, 0, -\strlen($search)) . $replacement; |
|
7415 | } |
||
7416 | |||
7417 | 11 | return $str; |
|
7418 | } |
||
13694 |