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 ( 331363...4b35f6 )
by Patrique
04:28
created

Headers   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 52
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Patoui\Router;
6
7
class Headers
8
{
9
    /** @var array */
10
    private array $headers;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
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, [__CLASS__, 'isServerKeyAHeader'], ARRAY_FILTER_USE_KEY);
24
        $headers = array_map([__CLASS__, 'wrapValuesInArray'], $headers);
25
        $headerKeys = array_map('strval', array_keys($headers));
26
        $headerKeys = array_map([__CLASS__, '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
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
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
55
    {
56
        return is_string($headerKey) ? str_replace('HTTP_', '', $headerKey) : '';
57
    }
58
}
59