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 ( 42d282...d7c54a )
by Patrique
01:00
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
    /* @var array */
10
    private $headers;
11
12
    public function __construct(array $headers = [])
13
    {
14
        $this->headers = $headers;
15
    }
16
17
    /**
18
     * Get headers from $_SERVER global
19
     * @return array
20
     */
21
    public static function getHeadersArrayFromGlobals(): array
22
    {
23
        $headers = array_filter($_SERVER, ['self', 'isServerKeyAHeader'], ARRAY_FILTER_USE_KEY);
24
        $headers = array_map(['self', 'wrapValuesInArray'], $headers);
25
        $headerKeys = array_map('strval', array_keys($headers));
26
        $headerKeys = array_map(['self', 'stripKeyOfLeadingHttpPrefix'], $headerKeys);
27
        $headerKeys = array_map('strval', array_values($headerKeys));
28
29
        return array_combine($headerKeys, $headers);
30
    }
31
32
    /**
33
     * @param string $serverParameter
34
     * @return bool
35
     */
36
    private static function isServerKeyAHeader(string $serverParameter): bool
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
37
    {
38
        return stripos($serverParameter, 'HTTP_') === 0;
39
    }
40
41
    /**
42
     * @param mixed $header
43
     * @return array
44
     */
45
    private static function wrapValuesInArray($header): array
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
46
    {
47
        return is_array($header) ? $header : [$header];
48
    }
49
50
    /**
51
     * @param mixed $headerKey
52
     * @return string
53
     */
54
    private static function stripKeyOfLeadingHttpPrefix($headerKey): string
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
55
    {
56
        return is_string($headerKey) ? str_replace('HTTP_', '', $headerKey) : '';
57
    }
58
}
59