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.

HeaderParse   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 20 6
A parse() 0 25 6
1
<?php
2
3
namespace Soheilrt\AdobeConnectClient\Client\Helpers;
4
5
/**
6
 * Parses a Header.
7
 *
8
 * See {@link https://github.com/guzzle/psr7}
9
 */
10
abstract class HeaderParse
11
{
12
    /**
13
     * Parse an array of header values containing ";" separated data into an
14
     * array of associative arrays representing the header key value pair
15
     * data of the header. When a parameter does not contain a value, but just
16
     * contains a key, this function will inject a key with a '' string value.
17
     *
18
     * @param string|array $header Header to parse into components.
19
     *
20
     * @return array Returns the parsed header values.
21
     */
22
    public static function parse($header)
23
    {
24
        static $trimmed = "\"'  \n\t\r";
25
        $params = $matches = [];
26
27
        foreach (static::normalize($header) as $val) {
28
            $part = [];
29
30
            foreach (preg_split('/;(?=([^"]*"[^"]*")*[^"]*$)/', $val) as $kvp) {
31
                if (preg_match_all('/<[^>]+>|[^=]+/', $kvp, $matches)) {
32
                    $m = $matches[0];
33
34
                    if (isset($m[1])) {
35
                        $part[trim($m[0], $trimmed)] = trim($m[1], $trimmed);
36
                    } else {
37
                        $part[] = trim($m[0], $trimmed);
38
                    }
39
                }
40
            }
41
            if ($part) {
42
                $params[] = $part;
43
            }
44
        }
45
46
        return $params;
47
    }
48
49
    /**
50
     * Converts an array of header values that may contain comma separated
51
     * headers into an array of headers with no comma separated values.
52
     *
53
     * @param string|array $header Header to normalize.
54
     *
55
     * @return array Returns the normalized header field values.
56
     */
57
    private static function normalize($header)
58
    {
59
        if (!is_array($header)) {
60
            return array_map('trim', explode(',', $header));
61
        }
62
        $result = [];
63
64
        foreach ($header as $value) {
65
            foreach ((array) $value as $v) {
66
                if (mb_strpos($v, ',') === false) {
67
                    $result[] = $v;
68
                    continue;
69
                }
70
                foreach (preg_split('/,(?=([^"]*"[^"]*")*[^"]*$)/', $v) as $vv) {
71
                    $result[] = trim($vv);
72
                }
73
            }
74
        }
75
76
        return $result;
77
    }
78
}
79