| Conditions | 12 | 
| Paths | 102 | 
| Total Lines | 42 | 
| Code Lines | 30 | 
| 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  | 
            ||
| 32 |     public static function factory(matrix $m): self { | 
            ||
| 33 |         if (!$m->isSquare()) { | 
            ||
| 34 |             throw new invalidArgumentException('Matrix must be given.'); | 
            ||
| 35 | }  | 
            ||
| 36 | $ipiv = vector::factory($m->col, vector::INT);  | 
            ||
| 37 | $ar = $m->copy();  | 
            ||
| 38 | $lp = lapack::getrf($ar, $ipiv);  | 
            ||
| 39 |         if ($lp != 0) { | 
            ||
| 40 | return null;  | 
            ||
| 41 | }  | 
            ||
| 42 | $l = matrix::factory($m->col, $m->col);  | 
            ||
| 43 | $u = matrix::factory($m->col, $m->col);  | 
            ||
| 44 | $p = matrix::factory($m->col, $m->col);  | 
            ||
| 45 |         for ($i = 0; $i < $m->col; ++$i) { | 
            ||
| 46 |             for ($j = 0; $j < $i; ++$j) { | 
            ||
| 47 | $l->data[$i * $m->col + $j] = $ar->data[$i * $m->col + $j];  | 
            ||
| 48 | }  | 
            ||
| 49 | $l->data[$i * $m->col + $i] = 1.0;  | 
            ||
| 50 |             for ($j = $i + 1; $j < $m->col; ++$j) { | 
            ||
| 51 | $l->data[$i * $m->col + $j] = 0.0;  | 
            ||
| 52 | }  | 
            ||
| 53 | }  | 
            ||
| 54 |         for ($i = 0; $i < $m->col; ++$i) { | 
            ||
| 55 |             for ($j = 0; $j < $i; ++$j) { | 
            ||
| 56 | $u->data[$i * $m->col + $j] = 0.0;  | 
            ||
| 57 | }  | 
            ||
| 58 |             for ($j = $i; $j < $m->col; ++$j) { | 
            ||
| 59 | $u->data[$i * $m->col + $j] = $ar->data[$i * $m->col + $j];  | 
            ||
| 60 | }  | 
            ||
| 61 | }  | 
            ||
| 62 |         for ($i = 0; $i < $m->col; ++$i) { | 
            ||
| 63 |             for ($j = 0; $j < $m->col; ++$j) { | 
            ||
| 64 |                 if ($j == $ipiv->data[$i] - 1) { | 
            ||
| 65 | $p->data[$i * $m->col + $j] = 1;  | 
            ||
| 66 |                 } else { | 
            ||
| 67 | $p->data[$i * $m->col + $j] = 0;  | 
            ||
| 68 | }  | 
            ||
| 69 | }  | 
            ||
| 70 | }  | 
            ||
| 71 | unset($ar);  | 
            ||
| 72 | unset($ipiv);  | 
            ||
| 73 | return new self($l, $u, $p);  | 
            ||
| 74 | }  | 
            ||
| 114 |