| Conditions | 11 |
| Paths | 21 |
| Total Lines | 31 |
| Code Lines | 21 |
| 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 |
||
| 57 | public static function formatMobiles($target) |
||
| 58 | { |
||
| 59 | if (!is_array($target)) { |
||
| 60 | return [$target]; |
||
| 61 | } |
||
| 62 | $list = []; |
||
| 63 | $nation = $number = null; |
||
| 64 | $count = count($target); |
||
| 65 | if ($count === 2) { |
||
| 66 | $firstItem = $target[0]; |
||
| 67 | if (is_int($firstItem) && $firstItem > 0 && $firstItem <= 9999) { |
||
| 68 | $nation = $firstItem; |
||
| 69 | $number = $target[1]; |
||
| 70 | } |
||
| 71 | if (is_string($firstItem) && strlen($firstItem = trim($firstItem)) <= 4) { |
||
| 72 | $nation = $firstItem; |
||
| 73 | $number = $target[1]; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | if (!is_null($nation)) { |
||
| 77 | return [compact('nation', 'number')]; |
||
| 78 | } |
||
| 79 | foreach ($target as $childTarget) { |
||
| 80 | $childList = self::formatMobiles($childTarget); |
||
| 81 | foreach ($childList as $childListItem) { |
||
| 82 | array_push($list, $childListItem); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | return $list; |
||
| 87 | } |
||
| 88 | } |
||
| 89 |