@@ -294,6 +294,23 @@ public static function formatCo2(float $grams): string
294294 return \number_format ($ grams , 2 ) . ' g CO₂ ' ;
295295 }
296296
297+ /**
298+ * Pad a string to a specified display width (handles multi-byte characters).
299+ *
300+ * @param string $string
301+ * @param int $width
302+ * @return string
303+ */
304+ private static function strPadDisplayWidth (string $ string , int $ width ): string
305+ {
306+ $ currentWidth = \mb_strwidth ($ string );
307+ if ($ currentWidth >= $ width ) {
308+ return $ string ;
309+ }
310+
311+ return $ string . \str_repeat (' ' , $ width - $ currentWidth );
312+ }
313+
297314 /**
298315 * Generate the formatted impact report string.
299316 *
@@ -308,17 +325,19 @@ public function generateReport(): string
308325 $ estimatedDataSaved = self ::formatBytesToGb ($ this ->getEstimatedDataSavedBytes ());
309326 $ co2Avoided = self ::formatCo2 ($ this ->getEstimatedCo2Avoided ());
310327
311- // Label column width for alignment
328+ // Label column display width for alignment
312329 $ labelWidth = 32 ;
330+ // Separator width
331+ $ separatorWidth = 43 ;
313332
314333 $ report = "Distribution impact " . PHP_EOL ;
315- $ report .= \str_repeat ('─ ' , $ labelWidth ) . PHP_EOL ;
316- $ report .= \str_pad ('Original archive: ' , $ labelWidth ) . ' ' . $ originalSize . PHP_EOL ;
317- $ report .= \str_pad ('Optimized archive: ' , $ labelWidth ) . ' ' . $ optimizedSize . PHP_EOL ;
318- $ report .= \str_pad ('Size reduction: ' , $ labelWidth ) . ' ' . $ reduction . PHP_EOL ;
319- $ report .= \str_pad ('Data saved/download: ' , $ labelWidth ) . ' ' . $ dataSaved . PHP_EOL ;
320- $ report .= \str_pad ('Estimated data saved: ' , $ labelWidth ) . ' ' . $ estimatedDataSaved . PHP_EOL ;
321- $ report .= \str_pad ('Estimated CO₂ emission avoided: ' , $ labelWidth ) . ' ' . $ co2Avoided . PHP_EOL ;
334+ $ report .= \str_repeat ('─ ' , $ separatorWidth ) . PHP_EOL ;
335+ $ report .= self :: strPadDisplayWidth ('Original archive: ' , $ labelWidth ) . $ originalSize . PHP_EOL ;
336+ $ report .= self :: strPadDisplayWidth ('Optimized archive: ' , $ labelWidth ) . $ optimizedSize . PHP_EOL ;
337+ $ report .= self :: strPadDisplayWidth ('Size reduction: ' , $ labelWidth ) . $ reduction . PHP_EOL ;
338+ $ report .= self :: strPadDisplayWidth ('Data saved/download: ' , $ labelWidth ) . $ dataSaved . PHP_EOL ;
339+ $ report .= self :: strPadDisplayWidth ('Estimated data saved: ' , $ labelWidth ) . $ estimatedDataSaved . PHP_EOL ;
340+ $ report .= self :: strPadDisplayWidth ('Estimated CO₂ emission avoided: ' , $ labelWidth ) . $ co2Avoided . PHP_EOL ;
322341
323342 return $ report ;
324343 }
0 commit comments