CookieList   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 15
dl 0
loc 50
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isSkipHeaderLine() 0 3 1
A createCollectionItem() 0 3 1
A getParams() 0 16 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\Cookie;
9
10
use Brownie\HttpClient\HeadList;
11
12
/**
13
 * HTTP cookie collection.
14
 */
15
class CookieList extends HeadList
16
{
17
18
    /**
19
     * Returns the HTTP header skip flag.
20
     *
21
     * @param string    $headerLine     HTTP header line.
22
     *
23
     * @return bool
24
     */
25 2
    protected function isSkipHeaderLine($headerLine)
26
    {
27 2
        return !$this->isHeaderSetCookie($headerLine);
28
    }
29
30
    /**
31
     * Creates a data model for the collection.
32
     *
33
     * @param string    $headerLine     HTTP header line.
34
     *
35
     * @return Cookie
36
     */
37 2
    public function createCollectionItem($headerLine)
38
    {
39 2
        return new Cookie($this->getParams($headerLine));
40
    }
41
42
    /**
43
     * Returns HTTP header parameters.
44
     *
45
     * @param string    $headerLine     HTTP header line.
46
     *
47
     * @return array
48
     */
49 2
    private function getParams($headerLine)
50
    {
51 2
        $cookieParamsStrings = explode(':', trim($headerLine), 2);
52 2
        $params = array();
53 2
        foreach (explode(';', trim($cookieParamsStrings[1])) as $index => $paramString) {
54 2
            $pairParam = explode('=', trim($paramString), 2);
55 2
            $name = strtolower(trim($pairParam[0]));
56 2
            $value = (!empty($pairParam[1]) ? trim($pairParam[1]) : true);
57 2
            if (0 == $index) {
58 2
                $params['name'] = $name;
59 2
                $params['value'] = $value;
60 2
                continue;
61
            }
62 1
            $params[$name] = $value;
63 2
        }
64 2
        return $params;
65
    }
66
}
67