percentageSaved > 0; } /** * Get the number of bytes saved. */ public function bytesSaved(): int { return $this->originalSize - $this->optimizedSize; } /** * Get human-readable summary. */ public function getSummary(): string { return sprintf( '%d%% saved (%s → %s)', $this->percentageSaved, $this->formatBytes($this->originalSize), $this->formatBytes($this->optimizedSize) ); } /** * Format bytes to human-readable size. */ protected function formatBytes(int $bytes): string { if ($bytes < 1024) { return $bytes.'B'; } if ($bytes < 1024 * 1024) { return round($bytes / 1024, 1).'KB'; } if ($bytes < 1024 * 1024 * 1024) { return round($bytes / (1024 * 1024), 1).'MB'; } return round($bytes / (1024 * 1024 * 1024), 2).'GB'; } /** * Convert to array for logging or storage. */ public function toArray(): array { return [ 'original_size' => $this->originalSize, 'optimized_size' => $this->optimizedSize, 'percentage_saved' => $this->percentageSaved, 'path' => $this->path, 'driver' => $this->driver, 'bytes_saved' => $this->bytesSaved(), ]; } }