Skip to content

Commit c600ab6

Browse files
localheinzsebastianbergmann
authored andcommitted
Fix: Do not pad lines of code coverage report
1 parent 842f726 commit c600ab6

9 files changed

+41
-48
lines changed

src/Report/Text.php

+13-20
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@
1010
namespace SebastianBergmann\CodeCoverage\Report;
1111

1212
use const PHP_EOL;
13-
use function array_map;
1413
use function date;
1514
use function ksort;
16-
use function max;
1715
use function sprintf;
18-
use function str_pad;
19-
use function strlen;
2016
use SebastianBergmann\CodeCoverage\CodeCoverage;
2117
use SebastianBergmann\CodeCoverage\Node\File;
2218
use SebastianBergmann\CodeCoverage\Util\Percentage;
@@ -160,31 +156,28 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
160156
$report->numberOfExecutableLines(),
161157
);
162158

163-
$padding = max(array_map('strlen', [$classes, $methods, $lines]));
164-
165159
if ($this->showOnlySummary) {
166-
$title = 'Code Coverage Report Summary:';
167-
$padding = max($padding, strlen($title));
160+
$title = 'Code Coverage Report Summary:';
168161

169-
$output .= $this->format($colors['header'], $padding, $title);
162+
$output .= $this->format($colors['header'], $title);
170163
} else {
171164
$date = date(' Y-m-d H:i:s');
172165
$title = 'Code Coverage Report:';
173166

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:');
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:');
178171
}
179172

180-
$output .= $this->format($colors['classes'], $padding, $classes);
181-
$output .= $this->format($colors['methods'], $padding, $methods);
173+
$output .= $this->format($colors['classes'], $classes);
174+
$output .= $this->format($colors['methods'], $methods);
182175

183176
if ($hasBranchCoverage) {
184-
$output .= $this->format($colors['paths'], $padding, $paths);
185-
$output .= $this->format($colors['branches'], $padding, $branches);
177+
$output .= $this->format($colors['paths'], $paths);
178+
$output .= $this->format($colors['branches'], $branches);
186179
}
187-
$output .= $this->format($colors['lines'], $padding, $lines);
180+
$output .= $this->format($colors['lines'], $lines);
188181

189182
if ($this->showOnlySummary) {
190183
return $output . PHP_EOL;
@@ -304,10 +297,10 @@ private function printCoverageCounts(int $numberOfCoveredElements, int $totalNum
304297
sprintf($format, $totalNumberOfElements) . ')';
305298
}
306299

307-
private function format(string $color, int $padding, false|string $string): string
300+
private function format(string $color, false|string $string): string
308301
{
309302
$reset = $color ? self::COLOR_RESET : '';
310303

311-
return $color . str_pad((string) $string, $padding) . $reset . PHP_EOL;
304+
return $color . (string) $string . $reset . PHP_EOL;
312305
}
313306
}

tests/_files/BankAccount-text-line.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22

3-
Code Coverage Report:
3+
Code Coverage Report:
44
%s
5-
6-
Summary:
5+
6+
Summary:
77
Classes: 0.00% (0/1)
88
Methods: 75.00% (3/4)
99
Lines: 62.50% (5/8)

tests/_files/BankAccount-text-path.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22

3-
Code Coverage Report:
3+
Code Coverage Report:
44
%s
5-
6-
Summary:
5+
6+
Summary:
77
Classes: 0.00% (0/1)
88
Methods: 75.00% (3/4)
99
Paths: 60.00% (3/5)
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22

33
Code Coverage Report Summary:
4-
Classes: 0.00% (0/1)
5-
Methods: 75.00% (3/4)
6-
Lines: 62.50% (5/8)
4+
Classes: 0.00% (0/1)
5+
Methods: 75.00% (3/4)
6+
Lines: 62.50% (5/8)
77

tests/_files/BankAccountWithUncovered-text-line.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22

3-
Code Coverage Report:
3+
Code Coverage Report:
44
%s
5-
6-
Summary:
7-
Classes: 0.00% (0/2)
8-
Methods: 37.50% (3/8)
5+
6+
Summary:
7+
Classes: 0.00% (0/2)
8+
Methods: 37.50% (3/8)
99
Lines: 31.25% (5/16)
1010

1111
BankAccount

tests/_files/BankAccountWithoutUncovered-text-line.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22

3-
Code Coverage Report:
3+
Code Coverage Report:
44
%s
5-
6-
Summary:
5+
6+
Summary:
77
Classes: 0.00% (0/1)
88
Methods: 75.00% (3/4)
99
Lines: 62.50% (5/8)

tests/_files/NamespacedBankAccount-text.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22

3-
Code Coverage Report:
3+
Code Coverage Report:
44
%s
5-
6-
Summary:
5+
6+
Summary:
77
Classes: 0.00% (0/1)
88
Methods: 75.00% (3/4)
99
Lines: 62.50% (5/8)

tests/_files/class-with-anonymous-function-text.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22

3-
Code Coverage Report:
3+
Code Coverage Report:
44
%s
5-
6-
Summary:
5+
6+
Summary:
77
Classes: 100.00% (1/1)
88
Methods: 100.00% (1/1)
99
Lines: 100.00% (8/8)

tests/_files/ignored-lines-text.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

3-
Code Coverage Report:%w
3+
Code Coverage Report:
44
%s
5-
%w
6-
Summary:%w
7-
Classes: (0/0)
8-
Methods: (0/0)
5+
6+
Summary:
7+
Classes: (0/0)
8+
Methods: (0/0)
99
Lines: 100.00% (1/1)
1010

0 commit comments

Comments
 (0)