Conditions | 7 |
Paths | 8 |
Total Lines | 19 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
22 | public static function obfuscate($string, $start = 0, $end = 3, $replacement = '*'): string |
||
23 | { |
||
24 | $len = \strlen($string); |
||
25 | |||
26 | if ($start < 0) { |
||
27 | $start += $len; |
||
28 | } |
||
29 | $start = min($start, $len - 1); |
||
30 | |||
31 | if ($end < 0) { |
||
32 | $end += $len; |
||
33 | } |
||
34 | $end = min($end, $len - 1); |
||
35 | |||
36 | if (0 === $len || $len === $start + 1 || $len === $end + 1 || $len <= $start + $end) { |
||
37 | return $string; |
||
38 | } |
||
39 | |||
40 | return substr($string, 0, $start).str_repeat($replacement, $len - $end - $start).substr($string, $len - $end, $end); |
||
41 | } |
||
43 |