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

CookieList   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
dl 0
loc 50
ccs 32
cts 32
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C initList() 0 44 12
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\Cookie;
9
10
use Brownie\Util\StorageList;
11
12
class CookieList extends StorageList
13
{
14
15
    /**
16
     * Initializing the cookies container.
17
     */
18 3
    protected function initList()
19
    {
20 3
        $cookieList = array();
21
22 3
        foreach (explode("\r\n", trim($this->getInitData())) as $headerLine) {
23 3
            if (empty($headerLine)) {
24 2
                $cookieList = array();
25 2
                continue;
26
            }
27 2
            if ('Set-Cookie:' != substr($headerLine, 0, 11)) {
28 2
                continue;
29
            }
30 2
            $cookieParams = explode(':', trim($headerLine), 2);
31 2
            $params = $cookieParams[1];
32
33 2
            $cookieParams = array();
34 2
            foreach (explode(';', trim($params)) as $index => $param) {
35 2
                $param = trim($param);
36 2
                $params = explode('=', $param, 2);
37 2
                $name = trim($params[0]);
38 2
                if (!empty($params[1])) {
39 2
                    $value = trim($params[1]);
40
                }
41 2
                if (0 == $index) {
42 2
                    $cookieParams['name'] = $name;
43 2
                    $cookieParams['value'] = $value;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.
Loading history...
44 2
                    continue;
45
                }
46
                switch ($name) {
47 1
                    case 'expires':
48 1
                    case 'path':
49 1
                    case 'domain':
50 1
                        $cookieParams[$name] = $value;
51 1
                        break;
52 1
                    case 'secure':
53 1
                    case 'httponly':
54 1
                        $cookieParams[$name] = true;
55 1
                        break;
56
                }
57
            }
58 2
            $cookieList[$cookieParams['name']] = new Cookie($cookieParams);
59
        }
60
61 3
        $this->setList($cookieList);
62 3
    }
63
}
64