Conditions | 12 |
Paths | 18 |
Total Lines | 44 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Tests | 32 |
CRAP Score | 12 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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; |
|
|
|||
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 | } |
|
64 |