Conditions | 16 |
Paths | 12289 |
Total Lines | 53 |
Code Lines | 36 |
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 |
||
60 | public static function compare($versionarray1, $versionarray2) |
||
61 | { |
||
62 | $ret = 0; |
||
63 | $level = 0; |
||
64 | $count1 = count($versionarray1); |
||
65 | $count2 = count($versionarray2); |
||
66 | $maxcount = max($count1, $count2); |
||
67 | while ($level < $maxcount) { |
||
68 | $operande1 = isset($versionarray1[$level]) ? $versionarray1[$level] : 0; |
||
69 | $operande2 = isset($versionarray2[$level]) ? $versionarray2[$level] : 0; |
||
70 | if (preg_match('/alpha|dev/i', $operande1)) { |
||
71 | $operande1 = -5; |
||
72 | } |
||
73 | if (preg_match('/alpha|dev/i', $operande2)) { |
||
74 | $operande2 = -5; |
||
75 | } |
||
76 | if (preg_match('/beta$/i', $operande1)) { |
||
77 | $operande1 = -4; |
||
78 | } |
||
79 | if (preg_match('/beta$/i', $operande2)) { |
||
80 | $operande2 = -4; |
||
81 | } |
||
82 | if (preg_match('/beta([0-9])+/i', $operande1)) { |
||
83 | $operande1 = -3; |
||
84 | } |
||
85 | if (preg_match('/beta([0-9])+/i', $operande2)) { |
||
86 | $operande2 = -3; |
||
87 | } |
||
88 | if (preg_match('/rc$/i', $operande1)) { |
||
89 | $operande1 = -2; |
||
90 | } |
||
91 | if (preg_match('/rc$/i', $operande2)) { |
||
92 | $operande2 = -2; |
||
93 | } |
||
94 | if (preg_match('/rc([0-9])+/i', $operande1)) { |
||
95 | $operande1 = -1; |
||
96 | } |
||
97 | if (preg_match('/rc([0-9])+/i', $operande2)) { |
||
98 | $operande2 = -1; |
||
99 | } |
||
100 | $level++; |
||
101 | //print 'level '.$level.' '.$operande1.'-'.$operande2.'<br>'; |
||
102 | if ($operande1 < $operande2) { |
||
103 | $ret = -$level; |
||
104 | break; |
||
105 | } |
||
106 | if ($operande1 > $operande2) { |
||
107 | $ret = $level; |
||
108 | break; |
||
109 | } |
||
110 | } |
||
111 | //print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret.'<br>'."\n"; |
||
112 | return $ret; |
||
113 | } |
||
138 |