GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

StringUtils   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 11
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B obfuscate() 0 19 7
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\Twig\Util;
13
14
final class StringUtils
15
{
16
    /**
17
     * @param string $string
18
     * @param int    $start
19
     * @param int    $end
20
     * @param string $replacement
21
     */
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
    }
42
}
43