get_request_header()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 4
nop 1
dl 0
loc 19
rs 9.3222
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace DaveRandom\Resume;
4
5
/**
6
 * Get the value of a header in the current request context
7
 *
8
 * @param string $name Name of the header
9
 * @return string|null Returns null when the header was not sent or cannot be retrieved
10
 * @codeCoverageIgnore
11
 */
12
function get_request_header(string $name)
13
{
14
    $name = \strtoupper($name);
15
16
    // IIS/Some Apache versions and configurations
17
    if (isset($_SERVER['HTTP_' . $name])) {
18
        return \trim($_SERVER['HTTP_' . $name]);
19
    }
20
21
    // Various other SAPIs
22
    if (\function_exists('apache_request_headers')) {
23
        foreach (\apache_request_headers() as $headerName => $value) {
24
            if (\strtoupper($headerName) === $name) {
25
                return \trim($value);
26
            }
27
        }
28
    }
29
30
    return null;
31
}
32