| Conditions | 12 |
| Paths | 297 |
| Total Lines | 45 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 78 | function show($descs) { |
||
| 79 | global $max_days; |
||
| 80 | $libc = []; |
||
| 81 | $libc2 = []; |
||
| 82 | $vbox = []; |
||
| 83 | $nv = 0; |
||
| 84 | foreach ($descs as $d) { |
||
| 85 | if (array_key_exists($d->libc, $libc)) { |
||
| 86 | $libc[$d->libc] += 1; |
||
| 87 | } else { |
||
| 88 | $libc[$d->libc] = 1; |
||
| 89 | } |
||
| 90 | if (!$d->vbox) continue; |
||
| 91 | $nv++; |
||
| 92 | if (array_key_exists($d->vbox, $vbox)) { |
||
| 93 | $vbox[$d->vbox] += 1; |
||
| 94 | } else { |
||
| 95 | $vbox[$d->vbox] = 1; |
||
| 96 | } |
||
| 97 | if (array_key_exists($d->libc, $libc2)) { |
||
| 98 | $libc2[$d->libc] += 1; |
||
| 99 | } else { |
||
| 100 | $libc2[$d->libc] = 1; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | $n = count($descs); |
||
| 105 | echo "$n Linux hosts active in last $max_days days\n"; |
||
| 106 | ksort($libc); |
||
| 107 | echo "libc versions:\n"; |
||
| 108 | foreach ($libc as $x=>$count) { |
||
| 109 | if (!$x) continue; |
||
| 110 | echo "$x: $count\n"; |
||
| 111 | } |
||
| 112 | ksort($vbox); |
||
| 113 | echo "vbox versions ($nv hosts):\n"; |
||
| 114 | foreach ($vbox as $x=>$count) { |
||
| 115 | if (!$x) continue; |
||
| 116 | echo "$x: $count\n"; |
||
| 117 | } |
||
| 118 | ksort($libc2); |
||
| 119 | echo "libc versions of hosts with vbox:\n"; |
||
| 120 | foreach ($libc2 as $x=>$count) { |
||
| 121 | if (!$x) continue; |
||
| 122 | echo "$x: $count\n"; |
||
| 123 | } |
||
| 128 |