@@ -29,8 +29,8 @@ final class ComparingRow
2929 public function __construct (string $ name , float $ old , float $ new )
3030 {
3131 $ this ->name = $ name ;
32- $ this ->old = round ($ old * 100 , 2 );
33- $ this ->new = round ($ new * 100 , 2 );
32+ $ this ->old = round ($ old , 2 );
33+ $ this ->new = round ($ new , 2 );
3434 $ this ->progress = $ this ->new - $ this ->old ;
3535 }
3636
@@ -58,9 +58,14 @@ public function getValues(): array
5858
5959 return [
6060 'name ' => $ this ->name ,
61- 'old ' => str_pad ( number_format ( $ this ->old , 2 ), 6 , ' ' , \ STR_PAD_LEFT ) . ' % ' ,
62- 'new ' => str_pad ( number_format ( $ this ->new , 2 ), 6 , ' ' , \ STR_PAD_LEFT ) . ' % ' ,
63- 'progress ' => str_pad ( $ progressPrefix . number_format ($ this ->progress , 2 ), 7 , ' ' , \ STR_PAD_LEFT ) . ' % ' ,
61+ 'old ' => $ this -> formatPercentage ( $ this ->old , 6 ) ,
62+ 'new ' => $ this -> formatPercentage ( $ this ->new , 6 ) ,
63+ 'progress ' => $ this -> formatPercentage ($ this ->progress , 7 , $ progressPrefix ) ,
6464 ];
6565 }
66+
67+ private function formatPercentage (float $ value , int $ length , string $ prefix = '' ): string
68+ {
69+ return str_pad ($ prefix . number_format ($ value , 2 , '. ' , '' ), $ length , ' ' , \STR_PAD_LEFT ) . ' % ' ;
70+ }
6671}
0 commit comments