Skip to content

Commit 29d5e6b

Browse files
committed
Fix: Do not pad lines of code coverage report
1 parent 842f726 commit 29d5e6b

10 files changed

+45
-41
lines changed

.psalm/baseline.xml

+5
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@
143143
<code>$tokens[$j - 1]</code>
144144
</InvalidArrayOffset>
145145
</file>
146+
<file src="src/Report/Text.php">
147+
<PossiblyFalseOperand>
148+
<code>$string</code>
149+
</PossiblyFalseOperand>
150+
</file>
146151
<file src="src/Report/Xml/BuildInformation.php">
147152
<PossiblyNullReference>
148153
<code>createElementNS</code>

src/Report/Text.php

+12-13
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use function ksort;
1616
use function max;
1717
use function sprintf;
18-
use function str_pad;
1918
use function strlen;
2019
use SebastianBergmann\CodeCoverage\CodeCoverage;
2120
use SebastianBergmann\CodeCoverage\Node\File;
@@ -166,25 +165,25 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
166165
$title = 'Code Coverage Report Summary:';
167166
$padding = max($padding, strlen($title));
168167

169-
$output .= $this->format($colors['header'], $padding, $title);
168+
$output .= $this->format($colors['header'], $title);
170169
} else {
171170
$date = date(' Y-m-d H:i:s');
172171
$title = 'Code Coverage Report:';
173172

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:');
173+
$output .= $this->format($colors['header'], $title);
174+
$output .= $this->format($colors['header'], $date);
175+
$output .= $this->format($colors['header'], '');
176+
$output .= $this->format($colors['header'], ' Summary:');
178177
}
179178

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

183182
if ($hasBranchCoverage) {
184-
$output .= $this->format($colors['paths'], $padding, $paths);
185-
$output .= $this->format($colors['branches'], $padding, $branches);
183+
$output .= $this->format($colors['paths'], $paths);
184+
$output .= $this->format($colors['branches'], $branches);
186185
}
187-
$output .= $this->format($colors['lines'], $padding, $lines);
186+
$output .= $this->format($colors['lines'], $lines);
188187

189188
if ($this->showOnlySummary) {
190189
return $output . PHP_EOL;
@@ -304,10 +303,10 @@ private function printCoverageCounts(int $numberOfCoveredElements, int $totalNum
304303
sprintf($format, $totalNumberOfElements) . ')';
305304
}
306305

307-
private function format(string $color, int $padding, false|string $string): string
306+
private function format(string $color, false|string $string): string
308307
{
309308
$reset = $color ? self::COLOR_RESET : '';
310309

311-
return $color . str_pad((string) $string, $padding) . $reset . PHP_EOL;
310+
return $color . $string . $reset . PHP_EOL;
312311
}
313312
}

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)