Skip to content

Commit d64b39f

Browse files
janedbalondrejmirtes
authored andcommitted
Nicer analysis time
1 parent 83aa36c commit d64b39f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Command/InceptionResult.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use PHPStan\DependencyInjection\Container;
66
use PHPStan\File\PathNotFoundException;
77
use PHPStan\Internal\BytesHelper;
8+
use function floor;
9+
use function implode;
810
use function max;
911
use function memory_get_peak_usage;
1012
use function microtime;
@@ -97,12 +99,29 @@ public function handleReturn(int $exitCode, ?int $peakMemoryUsageBytes, float $a
9799

98100
if ($this->getErrorOutput()->isDebug()) {
99101
$this->getErrorOutput()->writeLineFormatted(sprintf(
100-
'Analysis time: %0.1f seconds',
101-
round(microtime(true) - $analysisStartTime, 1),
102+
'Analysis time: %s',
103+
$this->formatDuration((int) round(microtime(true) - $analysisStartTime)),
102104
));
103105
}
104106

105107
return $exitCode;
106108
}
107109

110+
private function formatDuration(int $seconds): string
111+
{
112+
$minutes = (int) floor($seconds / 60);
113+
$remainingSeconds = $seconds % 60;
114+
115+
$result = [];
116+
if ($minutes > 0) {
117+
$result[] = $minutes . ' minute' . ($minutes > 1 ? 's' : '');
118+
}
119+
120+
if ($remainingSeconds > 0) {
121+
$result[] = $remainingSeconds . ' second' . ($remainingSeconds > 1 ? 's' : '');
122+
}
123+
124+
return implode(' ', $result);
125+
}
126+
108127
}

0 commit comments

Comments
 (0)