HeadersParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 34
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 0 26 5
1
<?php
2
3
/*
4
 * This file is part of the Ivory Http Adapter package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\HttpAdapter\Parser;
13
14
use Ivory\HttpAdapter\Asset\AbstractUninstantiableAsset;
15
use Ivory\HttpAdapter\Normalizer\HeadersNormalizer;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class HeadersParser extends AbstractUninstantiableAsset
21
{
22
    /**
23
     * @param array|string $headers
24
     *
25
     * @return array
26
     */
27 15786
    public static function parse($headers)
28
    {
29 15786
        if (is_string($headers)) {
30 2115
            $headers = explode("\r\n\r\n", trim($headers));
31
32 2115
            return explode("\r\n", end($headers));
33
        }
34
35 15705
        $parsedHeaders = [];
36
37 15705
        foreach ($headers as $name => $value) {
38 15642
            $value = HeadersNormalizer::normalizeHeaderValue($value);
39
40 15642
            if (is_int($name)) {
41 10774
                if (strpos($value, 'HTTP/') === 0) {
42 3078
                    $parsedHeaders = [$value];
43 2376
                } else {
44 10704
                    $parsedHeaders[] = $value;
45
                }
46 8304
            } else {
47 15586
                $parsedHeaders[] = $name.': '.$value;
48
            }
49 12103
        }
50
51 15705
        return $parsedHeaders;
52
    }
53
}
54