| Conditions | 21 |
| Paths | 35 |
| Total Lines | 65 |
| Code Lines | 50 |
| 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 |
||
| 89 | public static function compareArrays(array $a, array $b): int |
||
| 90 | { |
||
| 91 | reset($b); |
||
| 92 | foreach ($a as $av) { |
||
| 93 | if (key($b) === null) { |
||
| 94 | return 1; |
||
| 95 | } |
||
| 96 | $bv = current($b); |
||
| 97 | next($b); |
||
| 98 | if ($av === null) { |
||
| 99 | if ($bv !== null) { |
||
| 100 | return -1; |
||
| 101 | } |
||
| 102 | } elseif ($bv === null) { |
||
| 103 | return 1; |
||
| 104 | } elseif (is_array($av)) { |
||
| 105 | if (is_array($bv)) { |
||
| 106 | $comp = self::compareArrays($av, $bv); |
||
| 107 | if ($comp) { |
||
| 108 | return $comp; |
||
| 109 | } |
||
| 110 | } else { |
||
| 111 | return 1; |
||
| 112 | } |
||
| 113 | } elseif (is_array($bv)) { |
||
| 114 | return -1; |
||
| 115 | } else { |
||
| 116 | $comp = self::compareValues($av, $bv); |
||
| 117 | if ($comp != 0) { |
||
| 118 | return $comp; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | if (key($b) !== null) { |
||
| 123 | return -1; |
||
| 124 | } |
||
| 125 | |||
| 126 | // ties broken by the subscripts of the first item |
||
| 127 | $aFst = $a; |
||
| 128 | $bFst = $b; |
||
| 129 | do { |
||
| 130 | reset($aFst); |
||
| 131 | reset($bFst); |
||
| 132 | $ak = key($aFst); |
||
| 133 | $bk = key($bFst); |
||
| 134 | if ($ak === null && $bk === null) { |
||
| 135 | return 0; |
||
| 136 | } elseif ($ak === null) { |
||
| 137 | return -1; |
||
| 138 | } elseif ($bk === null) { |
||
| 139 | return 1; |
||
| 140 | } elseif (!is_numeric($ak) || !is_numeric($bk)) { |
||
| 141 | return 0; |
||
| 142 | } else { |
||
| 143 | $d = $ak - $bk; |
||
| 144 | if ($d) { |
||
| 145 | return $d; |
||
| 146 | } else { |
||
| 147 | $aFst = current($aFst); |
||
| 148 | $bFst = current($bFst); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } while (is_array($aFst) && is_array($bFst)); |
||
| 152 | |||
| 153 | return 0; |
||
| 154 | } |
||
| 156 |