| Conditions | 9 |
| Paths | 56 |
| Total Lines | 65 |
| 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 |
||
| 16 | public function dump(array $stats, array $total, $zoom = null, SymfonyStyle $outputHelper) |
||
| 17 | { |
||
| 18 | $headers = ['class', '01 BEST', '02 BEST', '03 BEST', '01 BAD', '02 BAD', '03 BAD', 'TOTAL RUN', 'TOTAL WAIT', 'RATE', 'POT. RATE']; |
||
| 19 | $data = []; |
||
| 20 | $globals = array_combine(array_keys($stats), array_column($stats, 'global')); |
||
| 21 | $maxGlobal = max($globals); |
||
| 22 | |||
| 23 | foreach ($stats as $class => $values) { |
||
| 24 | $path = explode('\\', $class); |
||
| 25 | $class = array_pop($path); |
||
| 26 | $times = array_merge($values['best_times'], $values['bad_times']); |
||
| 27 | foreach ($times as &$time) { |
||
| 28 | $time = (int) $time; |
||
| 29 | $time = ($time > 100) ? '<error>'.$time.' ms</error>' : $time.' ms'; |
||
| 30 | } |
||
| 31 | $global = $values['global']; |
||
| 32 | if ($global === $maxGlobal) { |
||
| 33 | $global = sprintf('<error>%d ms</error>', (int) $values['global']); |
||
| 34 | } else { |
||
| 35 | $global = ((int) $values['global']).' ms'; |
||
| 36 | } |
||
| 37 | $times[] = $global; |
||
| 38 | $times[] = ((int) $values['global_wait']).' ms'; |
||
| 39 | $data[] = array_merge([$values['position'].'. '.$class], $times, ['--', '--']); |
||
| 40 | } |
||
| 41 | |||
| 42 | $outputHelper->table($headers, $data); |
||
| 43 | |||
| 44 | $waits = array_combine(array_keys($stats), array_column($stats, 'global_wait')); |
||
| 45 | $maxWait = max($waits); |
||
| 46 | |||
| 47 | foreach ($waits as $i => $ms) |
||
| 48 | { |
||
| 49 | $waits[$i] = (int) $waits[$i]; |
||
| 50 | } |
||
| 51 | |||
| 52 | $reference = $maxWait / 100; |
||
| 53 | |||
| 54 | foreach ($waits as $class => $ms) { |
||
| 55 | if (0 !== $ms) { |
||
| 56 | $countPercents = (int) ($ms / $reference); |
||
| 57 | |||
| 58 | if ($countPercents < 1) { |
||
| 59 | $countPercents = 1; |
||
| 60 | } |
||
| 61 | echo $this->showBar($countPercents); |
||
| 62 | echo $this->showBar($countPercents); |
||
| 63 | echo $this->showBar($countPercents); |
||
| 64 | echo $this->showBar($countPercents); |
||
| 65 | echo $this->showBar($countPercents); |
||
| 66 | echo $this->showBar($countPercents); |
||
| 67 | echo $this->showBar($countPercents); |
||
| 68 | echo $this->showBar($countPercents); |
||
| 69 | echo $this->showBar($countPercents); |
||
| 70 | echo $this->showBarClass($class, $countPercents); |
||
| 71 | echo $this->showBar($countPercents); |
||
| 72 | echo $this->showBar($countPercents); |
||
| 73 | echo $this->showBar($countPercents); |
||
| 74 | echo $this->showBar($countPercents); |
||
| 75 | echo $this->showBar($countPercents); |
||
| 76 | echo $this->showBar($countPercents); |
||
| 77 | echo $this->showBar($countPercents); |
||
| 78 | echo $this->showBar($countPercents); |
||
| 79 | echo $this->showBar($countPercents); |
||
| 80 | echo $this->showBar($countPercents); |
||
| 81 | } |
||
| 108 | } |