From 29d5e6b1807f15733458baaf6b0ecb1d50457ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 9 Mar 2024 15:44:42 +0100 Subject: [PATCH] Fix: Do not pad lines of code coverage report --- .psalm/baseline.xml | 5 ++++ src/Report/Text.php | 25 +++++++++---------- tests/_files/BankAccount-text-line.txt | 6 ++--- tests/_files/BankAccount-text-path.txt | 6 ++--- tests/_files/BankAccount-text-summary.txt | 6 ++--- .../BankAccountWithUncovered-text-line.txt | 10 ++++---- .../BankAccountWithoutUncovered-text-line.txt | 6 ++--- tests/_files/NamespacedBankAccount-text.txt | 6 ++--- .../class-with-anonymous-function-text.txt | 6 ++--- tests/_files/ignored-lines-text.txt | 10 ++++---- 10 files changed, 45 insertions(+), 41 deletions(-) diff --git a/.psalm/baseline.xml b/.psalm/baseline.xml index 0dbf2f905..d64dad2ea 100644 --- a/.psalm/baseline.xml +++ b/.psalm/baseline.xml @@ -143,6 +143,11 @@ $tokens[$j - 1] + + + $string + + createElementNS diff --git a/src/Report/Text.php b/src/Report/Text.php index ab8daae73..b85c9c003 100644 --- a/src/Report/Text.php +++ b/src/Report/Text.php @@ -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; @@ -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; @@ -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; } } diff --git a/tests/_files/BankAccount-text-line.txt b/tests/_files/BankAccount-text-line.txt index 4f188c76c..cbc92cdab 100644 --- a/tests/_files/BankAccount-text-line.txt +++ b/tests/_files/BankAccount-text-line.txt @@ -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) diff --git a/tests/_files/BankAccount-text-path.txt b/tests/_files/BankAccount-text-path.txt index 488e34ff5..b18ac71cf 100644 --- a/tests/_files/BankAccount-text-path.txt +++ b/tests/_files/BankAccount-text-path.txt @@ -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) diff --git a/tests/_files/BankAccount-text-summary.txt b/tests/_files/BankAccount-text-summary.txt index 952abd17b..cf8e52385 100644 --- a/tests/_files/BankAccount-text-summary.txt +++ b/tests/_files/BankAccount-text-summary.txt @@ -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) diff --git a/tests/_files/BankAccountWithUncovered-text-line.txt b/tests/_files/BankAccountWithUncovered-text-line.txt index 85693d8af..ee7757bad 100644 --- a/tests/_files/BankAccountWithUncovered-text-line.txt +++ b/tests/_files/BankAccountWithUncovered-text-line.txt @@ -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 diff --git a/tests/_files/BankAccountWithoutUncovered-text-line.txt b/tests/_files/BankAccountWithoutUncovered-text-line.txt index 4f188c76c..cbc92cdab 100644 --- a/tests/_files/BankAccountWithoutUncovered-text-line.txt +++ b/tests/_files/BankAccountWithoutUncovered-text-line.txt @@ -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) diff --git a/tests/_files/NamespacedBankAccount-text.txt b/tests/_files/NamespacedBankAccount-text.txt index 7cede93cb..f535d120b 100644 --- a/tests/_files/NamespacedBankAccount-text.txt +++ b/tests/_files/NamespacedBankAccount-text.txt @@ -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) diff --git a/tests/_files/class-with-anonymous-function-text.txt b/tests/_files/class-with-anonymous-function-text.txt index 6d7e2a07e..905bdd1a2 100644 --- a/tests/_files/class-with-anonymous-function-text.txt +++ b/tests/_files/class-with-anonymous-function-text.txt @@ -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) diff --git a/tests/_files/ignored-lines-text.txt b/tests/_files/ignored-lines-text.txt index 55f57afbc..8592fb471 100644 --- a/tests/_files/ignored-lines-text.txt +++ b/tests/_files/ignored-lines-text.txt @@ -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)