Passed
Push — master ( 6a7e64...68c8aa )
by Oss
02:39
created

HeaderList::initList()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 8.6737
cc 5
eloc 15
nc 4
nop 0
crap 5
1
<?php
2
/**
3
 * @category    Brownie/HttpClient
4
 * @author      Brownie <[email protected]>
5
 * @license     http://www.gnu.org/copyleft/lesser.html
6
 */
7
8
namespace Brownie\HttpClient\Header;
9
10
use Brownie\Util\StorageList;
11
12
/**
13
 * HTTP headers collection.
14
 */
15
class HeaderList extends StorageList
16
{
17
18
    /**
19
     * Initializing the headers container.
20
     */
21 3
    protected function initList()
22
    {
23 3
        $headerList = array();
24 3
        foreach (explode("\r\n", trim($this->getInitData())) as $headerLine) {
25 3
            if (empty($headerLine)) {
26 1
                $headerList = array();
27 1
                continue;
28
            }
29
            if (
30 3
                ('HTTP/' == substr($headerLine, 0, 5)) ||
31 3
                ('Set-Cookie:' == substr($headerLine, 0, 11))
32
            ) {
33 1
                continue;
34
            }
35 3
            $headerParams = explode(':', trim($headerLine), 2);
36 3
            $key = trim($headerParams[0]);
37 3
            $headerList[strtolower($key)] = new Header(array(
38 3
                'name' => $key,
39 3
                'value' => trim($headerParams[1])
40
            ));
41
        }
42 3
        $this->setList($headerList);
43 3
    }
44
}
45