HeadList::initList()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 15
ccs 12
cts 12
cp 1
rs 9.9332
c 0
b 0
f 0
cc 4
nc 4
nop 0
crap 4
1
<?php
2
/**
3
 * @category    Brownie/HttpClient
4
 * @author      Brownie <[email protected]>
5
 * @license     https://opensource.org/licenses/MIT
6
 */
7
8
namespace Brownie\HttpClient;
9
10
use Brownie\Util\Exception\MethodNotImplementedException;
11
use Brownie\Util\StorageList;
12
13
/**
14
 * A wrapper for common lists of HTTP Headers.
15
 */
16
class HeadList extends StorageList
17
{
18
19
    /**
20
     * Initializing container.
21
     */
22 7
    protected function initList()
23
    {
24 7
        $list = array();
25 7
        foreach (explode("\r\n", trim($this->getInitData())) as $headerLine) {
26 7
            if (empty($headerLine)) {
27 3
                $list = array();
28 3
                continue;
29
            }
30 6
            if ($this->isSkipHeaderLine($headerLine)) {
31 3
                continue;
32
            }
33 5
            $item = $this->createCollectionItem($headerLine);
34 5
            $list[strtolower($item->getName())] = $item;
35 6
        }
36 6
        $this->setList($list);
37 6
    }
38
39
    /**
40
     * Returns the SetCookie flag of the HTTP header.
41
     *
42
     * @param string    $headerLine     HTTP header line.
43
     *
44
     * @return bool
45
     */
46 5
    protected function isHeaderSetCookie($headerLine)
47
    {
48 5
        return ('Set-Cookie:' == substr($headerLine, 0, 11));
49
    }
50
51
    /**
52
     * Returns the HTTP flag of the header.
53
     *
54
     * @param string    $headerLine     HTTP header line.
55
     *
56
     * @return bool
57
     */
58 3
    protected function isHeaderHTTP($headerLine)
59
    {
60 3
        return ('HTTP/' == substr($headerLine, 0, 5));
61
    }
62
63
    /**
64
     * Returns the HTTP header skip flag.
65
     *
66
     * @param string    $headerLine     HTTP header line.
67
     *
68
     * @return bool
69
     *
70
     * @throws MethodNotImplementedException
71
     */
72 1
    protected function isSkipHeaderLine($headerLine)
73
    {
74 1
        throw new MethodNotImplementedException('Method not implemented');
75
    }
76
77
    /**
78
     * Creates a data model for the collection.
79
     *
80
     * @param string    $headerLine     HTTP header line.
81
     *
82
     * @return mixed
83
     *
84
     * @throws MethodNotImplementedException
85
     */
86 1
    public function createCollectionItem($headerLine)
87
    {
88 1
        throw new MethodNotImplementedException('Method not implemented');
89
    }
90
}
91