Passed
Push — master ( c65e58...1194b0 )
by Oss
02:24
created

HeaderList::getHeaderParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
crap 1
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\HttpClient\HeadList;
11
12
/**
13
 * HTTP headers collection.
14
 */
15
class HeaderList extends HeadList
16
{
17
18
    /**
19
     * Initializing the headers container.
20
     */
21 3 View Code Duplication
    protected function initList()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 3
            if ($this->isHeaderHTTP($headerLine) || $this->isHeaderSetCookie($headerLine)) {
30 1
                continue;
31
            }
32 3
            $headerParams = $this->getHeaderParams($headerLine);
33 3
            $headerList[strtolower($headerParams['name'])] = new Header($headerParams);
34
        }
35 3
        $this->setList($headerList);
36 3
    }
37
38
    /**
39
     * Splits Cookie HTTP header on the parameters.
40
     *
41
     * @param string    $headerLine     HTTP header line.
42
     *
43
     * @return array
44
     */
45 3
    private function getHeaderParams($headerLine)
46
    {
47 3
        $pairParam = explode(':', trim($headerLine), 2);
48 3
        $name = trim($pairParam[0]);
49 3
        $value = trim($pairParam[1]);
50
        return array(
51 3
            'name' => $name,
52 3
            'value' => $value
53
        );
54
    }
55
}
56