| Conditions | 20 |
| Paths | 64 |
| Total Lines | 56 |
| Lines | 6 |
| Ratio | 10.71 % |
| 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 |
||
| 118 | public static function compareIdentifiers(array $left, array $right) |
||
| 119 | { |
||
| 120 | if ($left && empty($right)) { |
||
|
|
|||
| 121 | return self::LESS_THAN; |
||
| 122 | } elseif (empty($left) && $right) { |
||
| 123 | return self::GREATER_THAN; |
||
| 124 | } |
||
| 125 | |||
| 126 | $l = $left; |
||
| 127 | $r = $right; |
||
| 128 | $x = self::GREATER_THAN; |
||
| 129 | $y = self::LESS_THAN; |
||
| 130 | |||
| 131 | if (count($l) < count($r)) { |
||
| 132 | $l = $right; |
||
| 133 | $r = $left; |
||
| 134 | $x = self::LESS_THAN; |
||
| 135 | $y = self::GREATER_THAN; |
||
| 136 | } |
||
| 137 | |||
| 138 | foreach (array_keys($l) as $i) { |
||
| 139 | if (!isset($r[$i])) { |
||
| 140 | return $x; |
||
| 141 | } |
||
| 142 | |||
| 143 | if ($l[$i] === $r[$i]) { |
||
| 144 | continue; |
||
| 145 | } |
||
| 146 | |||
| 147 | View Code Duplication | if (true === ($li = (false != preg_match('/^\d+$/', $l[$i])))) { |
|
| 148 | $l[$i] = intval($l[$i]); |
||
| 149 | } |
||
| 150 | |||
| 151 | View Code Duplication | if (true === ($ri = (false != preg_match('/^\d+$/', $r[$i])))) { |
|
| 152 | $r[$i] = intval($r[$i]); |
||
| 153 | } |
||
| 154 | |||
| 155 | if ($li && $ri) { |
||
| 156 | return ($l[$i] > $r[$i]) ? $x : $y; |
||
| 157 | } elseif (!$li && $ri) { |
||
| 158 | return $x; |
||
| 159 | } elseif ($li && !$ri) { |
||
| 160 | return $y; |
||
| 161 | } |
||
| 162 | |||
| 163 | $result = strcmp($l[$i], $r[$i]); |
||
| 164 | |||
| 165 | if ($result > 0) { |
||
| 166 | return $x; |
||
| 167 | } elseif ($result < 0) { |
||
| 168 | return $y; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | return self::EQUAL_TO; |
||
| 173 | } |
||
| 174 | } |
||
| 175 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.