|
10 | 10 | namespace SebastianBergmann\CodeCoverage\Report;
|
11 | 11 |
|
12 | 12 | use const PHP_EOL;
|
| 13 | +use function array_map; |
13 | 14 | use function date;
|
14 | 15 | use function ksort;
|
| 16 | +use function max; |
15 | 17 | use function sprintf;
|
| 18 | +use function str_pad; |
| 19 | +use function strlen; |
16 | 20 | use SebastianBergmann\CodeCoverage\CodeCoverage;
|
17 | 21 | use SebastianBergmann\CodeCoverage\Node\File;
|
18 | 22 | use SebastianBergmann\CodeCoverage\Util\Percentage;
|
@@ -156,28 +160,31 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
|
156 | 160 | $report->numberOfExecutableLines(),
|
157 | 161 | );
|
158 | 162 |
|
| 163 | + $padding = max(array_map('strlen', [$classes, $methods, $lines])); |
| 164 | + |
159 | 165 | if ($this->showOnlySummary) {
|
160 |
| - $title = 'Code Coverage Report Summary:'; |
| 166 | + $title = 'Code Coverage Report Summary:'; |
| 167 | + $padding = max($padding, strlen($title)); |
161 | 168 |
|
162 |
| - $output .= $this->format($colors['header'], $title); |
| 169 | + $output .= $this->format($colors['header'], $padding, $title); |
163 | 170 | } else {
|
164 | 171 | $date = date(' Y-m-d H:i:s');
|
165 | 172 | $title = 'Code Coverage Report:';
|
166 | 173 |
|
167 |
| - $output .= $this->format($colors['header'], $title); |
168 |
| - $output .= $this->format($colors['header'], $date); |
169 |
| - $output .= $this->format($colors['header'], ''); |
170 |
| - $output .= $this->format($colors['header'], ' Summary:'); |
| 174 | + $output .= $this->format($colors['header'], $padding, $title); |
| 175 | + $output .= $this->format($colors['header'], $padding, $date); |
| 176 | + $output .= $this->format($colors['header'], $padding, ''); |
| 177 | + $output .= $this->format($colors['header'], $padding, ' Summary:'); |
171 | 178 | }
|
172 | 179 |
|
173 |
| - $output .= $this->format($colors['classes'], $classes); |
174 |
| - $output .= $this->format($colors['methods'], $methods); |
| 180 | + $output .= $this->format($colors['classes'], $padding, $classes); |
| 181 | + $output .= $this->format($colors['methods'], $padding, $methods); |
175 | 182 |
|
176 | 183 | if ($hasBranchCoverage) {
|
177 |
| - $output .= $this->format($colors['paths'], $paths); |
178 |
| - $output .= $this->format($colors['branches'], $branches); |
| 184 | + $output .= $this->format($colors['paths'], $padding, $paths); |
| 185 | + $output .= $this->format($colors['branches'], $padding, $branches); |
179 | 186 | }
|
180 |
| - $output .= $this->format($colors['lines'], $lines); |
| 187 | + $output .= $this->format($colors['lines'], $padding, $lines); |
181 | 188 |
|
182 | 189 | if ($this->showOnlySummary) {
|
183 | 190 | return $output . PHP_EOL;
|
@@ -297,10 +304,12 @@ private function printCoverageCounts(int $numberOfCoveredElements, int $totalNum
|
297 | 304 | sprintf($format, $totalNumberOfElements) . ')';
|
298 | 305 | }
|
299 | 306 |
|
300 |
| - private function format(string $color, false|string $string): string |
| 307 | + private function format(string $color, int $padding, false|string $string): string |
301 | 308 | {
|
302 |
| - $reset = $color ? self::COLOR_RESET : ''; |
| 309 | + if ($color === '') { |
| 310 | + return (string) $string . PHP_EOL; |
| 311 | + } |
303 | 312 |
|
304 |
| - return $color . (string) $string . $reset . PHP_EOL; |
| 313 | + return $color . str_pad((string) $string, $padding) . self::COLOR_RESET . PHP_EOL; |
305 | 314 | }
|
306 | 315 | }
|
0 commit comments