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.
Completed
Push — master ( 22b6cf...443b3e )
by Patrique
04:42
created

Headers::isServerKeyAHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Patoui\Router;
6
7
class Headers
8
{
9
    /**
10
     * Get headers from $_SERVER global.
11
     * @return array<array>
12
     */
13
    public static function getHeadersArrayFromGlobals(): array
14
    {
15
        $headers = array_filter($_SERVER, [__CLASS__, 'isServerKeyAHeader'], ARRAY_FILTER_USE_KEY);
16
        $headers = array_map([__CLASS__, 'wrapValuesInArray'], $headers);
17
        $headerKeys = array_map('strval', array_keys($headers));
18
        $headerKeys = array_map([__CLASS__, 'stripKeyOfLeadingHttpPrefix'], $headerKeys);
19
20
        /** @var array<array> $headers */
21
        $headers = array_values($headers);
22
23
        /** @var array<string> $headerKeys */
24
        $headerKeys = array_map(static function ($headerKey) {
25
            return (string) $headerKey;
26
        }, array_values($headerKeys));
27
28
        $formattedHeaders = array_combine($headerKeys, $headers);
29
30
        if ($formattedHeaders === false) {
31
            return [];
32
        }
33
34
        return $formattedHeaders;
35
    }
36
37
    /**
38
     * @param string $serverParameter
39
     * @return bool
40
     */
41
    private static function isServerKeyAHeader(string $serverParameter): bool
42
    {
43
        return stripos($serverParameter, 'HTTP_') === 0;
44
    }
45
46
    /**
47
     * @param mixed $header
48
     * @return array<mixed>
49
     */
50
    private static function wrapValuesInArray($header): array
51
    {
52
        return is_array($header) ? $header : [$header];
53
    }
54
55
    /**
56
     * @param mixed $headerKey
57
     * @return string
58
     */
59
    private static function stripKeyOfLeadingHttpPrefix($headerKey): string
60
    {
61
        return is_string($headerKey) ? str_replace('HTTP_', '', $headerKey) : '';
62
    }
63
}
64