| Conditions | 13 |
| Paths | 256 |
| Total Lines | 15 |
| Code Lines | 10 |
| Lines | 3 |
| Ratio | 20 % |
| 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 |
||
| 86 | private static function getNeighborIndexes($matrix, $i, $j) |
||
| 87 | { |
||
| 88 | |||
| 89 | $indexes = []; |
||
| 90 | |||
| 91 | if ($i > 0 && $j > 0) array_push($indexes, [$i - 1, $j - 1]); |
||
| 92 | if ($i > 0) array_push($indexes, [$i - 1, $j]); |
||
| 93 | View Code Duplication | if ($i > 0 && $j < sizeof($matrix[0]) - 1) array_push($indexes, [$i - 1, $j + 1]); |
|
| 94 | if ($j > 0) array_push($indexes, [$i, $j - 1]); |
||
| 95 | if ($j < sizeof($matrix[0]) - 1) array_push($indexes, [$i, $j + 1]); |
||
| 96 | View Code Duplication | if ($i < sizeof($matrix) - 1 && $j > 0) array_push($indexes, [$i + 1, $j - 1]); |
|
| 97 | if ($i < sizeof($matrix) - 1) array_push($indexes, [$i + 1, $j]); |
||
| 98 | View Code Duplication | if ($i < sizeof($matrix) - 1 && $j < sizeof($matrix[0]) - 1) array_push($indexes, [$i + 1, $j + 1]); |
|
| 99 | |||
| 100 | return $indexes; |
||
| 101 | } |
||
| 104 | } |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: