Conditions | 10 |
Paths | 3 |
Total Lines | 35 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
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 |
||
26 | public static function factory(\Np\matrix $m): matrix { |
||
27 | $lead = 0; |
||
28 | $ar = $m->copy(); |
||
29 | for ($r = 0; $r < $ar->row; ++$r) { |
||
30 | if ($lead >= $ar->col) |
||
31 | break; { |
||
32 | $i = $r; |
||
33 | while ($ar->data[$i * $ar->col + $lead] == 0) { |
||
34 | $i++; |
||
35 | if ($i == $ar->row) { |
||
36 | $i = $r; |
||
37 | $lead++; |
||
38 | if ($lead == $ar->col) { |
||
39 | return $ar; |
||
40 | } |
||
41 | } |
||
42 | } |
||
43 | $ar->swapRows($r, $i); |
||
44 | } { |
||
45 | $lv = $ar->data[$r * $ar->col + $lead]; |
||
46 | for ($j = 0; $j < $ar->col; ++$j) { |
||
47 | $ar->data[$r * $ar->col + $j] = $ar->data[$r * $ar->col + $j] / $lv; |
||
48 | } |
||
49 | } |
||
50 | for ($i = 0; $i < $ar->row; ++$i) { |
||
51 | if ($i != $r) { |
||
52 | $lv = $ar->data[$i * $ar->col + $lead]; |
||
53 | for ($j = 0; $j < $ar->col; ++$j) { |
||
54 | $ar->data[$i * $ar->col + $j] -= $lv * $ar->data[$r * $ar->col + $j]; |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | $lead++; |
||
59 | } |
||
60 | return $ar; |
||
61 | } |
||
63 |