Skip to content

Nicer analysis time output #3242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/Command/InceptionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use PHPStan\DependencyInjection\Container;
use PHPStan\File\PathNotFoundException;
use PHPStan\Internal\BytesHelper;
use function floor;
use function implode;
use function max;
use function memory_get_peak_usage;
use function microtime;
Expand Down Expand Up @@ -97,12 +99,29 @@ public function handleReturn(int $exitCode, ?int $peakMemoryUsageBytes, float $a

if ($this->getErrorOutput()->isDebug()) {
$this->getErrorOutput()->writeLineFormatted(sprintf(
'Analysis time: %0.1f seconds',
round(microtime(true) - $analysisStartTime, 1),
'Analysis time: %s',
$this->formatDuration((int) round(microtime(true) - $analysisStartTime)),
));
}

return $exitCode;
}

private function formatDuration(int $seconds): string
{
$minutes = (int) floor($seconds / 60);
$remainingSeconds = $seconds % 60;

$result = [];
if ($minutes > 0) {
$result[] = $minutes . ' minute' . ($minutes > 1 ? 's' : '');
}

if ($remainingSeconds > 0) {
$result[] = $remainingSeconds . ' second' . ($remainingSeconds > 1 ? 's' : '');
}

return implode(' ', $result);
}

}
Loading