Skip to content

Commit

Permalink
Fix: Do not pad lines of code coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Mar 9, 2024
1 parent 842f726 commit 29d5e6b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .psalm/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@
<code>$tokens[$j - 1]</code>
</InvalidArrayOffset>
</file>
<file src="src/Report/Text.php">
<PossiblyFalseOperand>
<code>$string</code>
</PossiblyFalseOperand>
</file>
<file src="src/Report/Xml/BuildInformation.php">
<PossiblyNullReference>
<code>createElementNS</code>
Expand Down
25 changes: 12 additions & 13 deletions src/Report/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use function ksort;
use function max;
use function sprintf;
use function str_pad;
use function strlen;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Node\File;
Expand Down Expand Up @@ -166,25 +165,25 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
$title = 'Code Coverage Report Summary:';
$padding = max($padding, strlen($title));

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

$output .= $this->format($colors['header'], $padding, $title);
$output .= $this->format($colors['header'], $padding, $date);
$output .= $this->format($colors['header'], $padding, '');
$output .= $this->format($colors['header'], $padding, ' Summary:');
$output .= $this->format($colors['header'], $title);
$output .= $this->format($colors['header'], $date);
$output .= $this->format($colors['header'], '');
$output .= $this->format($colors['header'], ' Summary:');
}

$output .= $this->format($colors['classes'], $padding, $classes);
$output .= $this->format($colors['methods'], $padding, $methods);
$output .= $this->format($colors['classes'], $classes);
$output .= $this->format($colors['methods'], $methods);

if ($hasBranchCoverage) {
$output .= $this->format($colors['paths'], $padding, $paths);
$output .= $this->format($colors['branches'], $padding, $branches);
$output .= $this->format($colors['paths'], $paths);
$output .= $this->format($colors['branches'], $branches);
}
$output .= $this->format($colors['lines'], $padding, $lines);
$output .= $this->format($colors['lines'], $lines);

if ($this->showOnlySummary) {
return $output . PHP_EOL;
Expand Down Expand Up @@ -304,10 +303,10 @@ private function printCoverageCounts(int $numberOfCoveredElements, int $totalNum
sprintf($format, $totalNumberOfElements) . ')';
}

private function format(string $color, int $padding, false|string $string): string
private function format(string $color, false|string $string): string
{
$reset = $color ? self::COLOR_RESET : '';

return $color . str_pad((string) $string, $padding) . $reset . PHP_EOL;
return $color . $string . $reset . PHP_EOL;
}
}
6 changes: 3 additions & 3 deletions tests/_files/BankAccount-text-line.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


Code Coverage Report:
Code Coverage Report:
%s
Summary:

Summary:
Classes: 0.00% (0/1)
Methods: 75.00% (3/4)
Lines: 62.50% (5/8)
Expand Down
6 changes: 3 additions & 3 deletions tests/_files/BankAccount-text-path.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


Code Coverage Report:
Code Coverage Report:
%s
Summary:

Summary:
Classes: 0.00% (0/1)
Methods: 75.00% (3/4)
Paths: 60.00% (3/5)
Expand Down
6 changes: 3 additions & 3 deletions tests/_files/BankAccount-text-summary.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


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

10 changes: 5 additions & 5 deletions tests/_files/BankAccountWithUncovered-text-line.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@


Code Coverage Report:
Code Coverage Report:
%s
Summary:
Classes: 0.00% (0/2)
Methods: 37.50% (3/8)

Summary:
Classes: 0.00% (0/2)
Methods: 37.50% (3/8)
Lines: 31.25% (5/16)

BankAccount
Expand Down
6 changes: 3 additions & 3 deletions tests/_files/BankAccountWithoutUncovered-text-line.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


Code Coverage Report:
Code Coverage Report:
%s
Summary:

Summary:
Classes: 0.00% (0/1)
Methods: 75.00% (3/4)
Lines: 62.50% (5/8)
Expand Down
6 changes: 3 additions & 3 deletions tests/_files/NamespacedBankAccount-text.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


Code Coverage Report:
Code Coverage Report:
%s
Summary:

Summary:
Classes: 0.00% (0/1)
Methods: 75.00% (3/4)
Lines: 62.50% (5/8)
Expand Down
6 changes: 3 additions & 3 deletions tests/_files/class-with-anonymous-function-text.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


Code Coverage Report:
Code Coverage Report:
%s
Summary:

Summary:
Classes: 100.00% (1/1)
Methods: 100.00% (1/1)
Lines: 100.00% (8/8)
Expand Down
10 changes: 5 additions & 5 deletions tests/_files/ignored-lines-text.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@


Code Coverage Report:%w
Code Coverage Report:
%s
%w
Summary:%w
Classes: (0/0)
Methods: (0/0)

Summary:
Classes: (0/0)
Methods: (0/0)
Lines: 100.00% (1/1)

0 comments on commit 29d5e6b

Please sign in to comment.