Conditions | 10 |
Paths | 14 |
Total Lines | 47 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
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 |
||
38 | public function parse() |
||
39 | { |
||
40 | $diffs = array(); |
||
41 | $diff = null; |
||
|
|||
42 | $collected = array(); |
||
43 | |||
44 | for ($i = 0; $i < $this->lineCount; ++$i) { |
||
45 | if (preg_match('(^---\\s+(?P<file>.+))', $this->lines[$i], $matchFileA) && |
||
46 | preg_match('(^\\+\\+\\+\\s+(?P<file>.+))', $this->lines[$i + 1], $matchFileB)) { |
||
47 | |||
48 | //Second iteration |
||
49 | if (count($collected) > 0 && count($diffs) > 0) { |
||
50 | $lastDiff = end($diffs); |
||
51 | $diffLines = $this->parseDiffLines($collected); |
||
52 | $lastDiff->setDiffLines($diffLines); |
||
53 | reset($diffs); |
||
54 | } |
||
55 | |||
56 | //All iteration |
||
57 | $diff = new GitDiff(); |
||
58 | $diff->setFileA($matchFileA['file']); |
||
59 | $diff->setFileB($matchFileB['file']); |
||
60 | $diffs[] = $diff; |
||
61 | |||
62 | $collected = array(); |
||
63 | |||
64 | ++$i; |
||
65 | |||
66 | if ($i >= 300000) { |
||
67 | break; |
||
68 | } |
||
69 | } else { |
||
70 | if (preg_match('/^(?:diff --git |index [\da-f\.]+|[+-]{3} [ab])/', $this->lines[$i])) { |
||
71 | continue; |
||
72 | } |
||
73 | $collected[] = $this->lines[$i]; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | if (count($collected) > 0 && count($diffs) > 0) { |
||
78 | $lastDiff = end($diffs); |
||
79 | $diffLines = $this->parseDiffLines($collected); |
||
80 | $lastDiff->setDiffLines($diffLines); |
||
81 | reset($diffs); |
||
82 | } |
||
83 | |||
84 | return $diffs; |
||
85 | } |
||
143 |