Conditions | 12 |
Paths | 13 |
Total Lines | 35 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 2 | Features | 1 |
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 |
||
39 | private function parseHeader($key, $value) |
||
40 | { |
||
41 | switch ($key) { |
||
42 | case 'msgno': |
||
43 | return (int)$value; |
||
44 | case 'answered': |
||
45 | // no break |
||
46 | case 'deleted': |
||
47 | // no break |
||
48 | case 'draft': |
||
49 | // no break |
||
50 | case 'unseen': |
||
51 | return (bool)trim($value); |
||
52 | case 'date': |
||
53 | $value = $this->decode($value); |
||
54 | $value = preg_replace('/([^\(]*)\(.*\)/', '$1', $value); |
||
55 | |||
56 | return new \DateTime($value); |
||
57 | case 'from': |
||
58 | return $this->decodeEmailAddress(current($value)); |
||
59 | case 'to': |
||
60 | // no break |
||
61 | case 'cc': |
||
62 | $emails = []; |
||
63 | foreach ($value as $address) { |
||
64 | $emails[] = $this->decodeEmailAddress($address); |
||
65 | } |
||
66 | |||
67 | return $emails; |
||
68 | case 'subject': |
||
69 | return $this->decode($value); |
||
70 | default: |
||
71 | return $value; |
||
72 | } |
||
73 | } |
||
74 | |||
84 |