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

CookieList::initList()   C

Complexity

Conditions 12
Paths 18

Size

Total Lines 44
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 32
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 44
ccs 32
cts 32
cp 1
rs 5.1612
cc 12
eloc 32
nc 18
nop 0
crap 12

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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