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.

CacheKey::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\Cache;
4
5
use Psr\Http\Message\UriInterface;
6
7
final class CacheKey
8
{
9
    /**
10
     * Create a cache key based on the URI and glue.
11
     *
12
     * @param  UriInterface $uri
13
     * @param  string       $glue
14
     * @return string
15
     */
16 6
    public static function create(UriInterface $uri, string $glue): string
17
    {
18 6
        return self::stripExtraSlashes(
19 6
            \implode(
20 6
                $glue,
21
                [
22 6
                    (string)$uri->getScheme(),
23 6
                    (string)$uri->getHost(),
24 6
                    (string)$uri->getPort(),
25 6
                    self::chunkUp(\md5((string)$uri->getPath()), $glue),
26 6
                    self::chunkUp(\md5((string)$uri->getQuery()), $glue),
27
                ]
28
            ),
29 6
            $glue
30
        );
31
    }
32
33
    /**
34
     * @param  string $string
35
     * @param  string $glue
36
     * @return string
37
     */
38 6
    private static function chunkUp(string $string, string $glue): string
39
    {
40 6
        return \implode($glue, \str_split($string, 2));
41
    }
42
43
    /**
44
     * @param  string $string
45
     * @return string
46
     */
47 6
    private static function stripExtraSlashes(string $string, string $glue): string
48
    {
49 6
        return \preg_replace('#' . $glue . '+#', $glue, $string);
50
    }
51
}
52