Conditions | 10 |
Paths | 8 |
Total Lines | 41 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 24 |
CRAP Score | 10 |
Changes | 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 |
||
20 | 2 | public function parseLines(array $lines) |
|
21 | { |
||
22 | 2 | $this->getHistory()->initTags(); |
|
23 | |||
24 | 2 | $no = 0; |
|
25 | 2 | foreach ($lines as $str) { |
|
26 | 2 | $str = rtrim($str); |
|
27 | 2 | ++$no; |
|
28 | |||
29 | /// skip empty lines |
||
30 | 2 | if (!$str) { |
|
31 | /// headers |
||
32 | 2 | } elseif ($no <= 2 || preg_match('/^# /', $str)) { |
|
33 | 2 | $this->addHeader($str); |
|
34 | |||
35 | /// links |
||
36 | 2 | } elseif (preg_match('/^\[(.*?)\]:\s*(.*)$/', $str, $m)) { |
|
37 | 2 | $this->addLink($m[1], $m[2]); |
|
38 | |||
39 | /// tags |
||
40 | 2 | } elseif ( |
|
41 | 2 | preg_match('/^##\s+\[(.+?)\]\s*-?\s*(.*)$/', $str, $m) || |
|
42 | 2 | preg_match('/^##\s+(\S+?)\s*-\s*(.*)$/', $str, $m) |
|
43 | 2 | ) { |
|
44 | 2 | $this->addTag($m[1], $m[2]); |
|
45 | |||
46 | /// notes |
||
47 | 2 | } elseif (preg_match('/^-\s+(.*)$/', $str, $m)) { |
|
48 | 2 | $this->addNote($m[1]); |
|
49 | |||
50 | /// commits |
||
51 | 2 | } elseif (preg_match('/^\s+-\s+\[?([0-9a-fA-F]{7})\]?\s*(.*)$/', $str, $m)) { |
|
52 | 2 | $this->addCommit($m[1], $m[2]); |
|
53 | |||
54 | /// comments |
||
55 | 2 | } else { |
|
56 | 2 | $this->addComment($str); |
|
57 | } |
||
58 | 2 | } |
|
59 | |||
60 | 2 | return $this->getHistory(); |
|
61 | } |
||
63 |