diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eabdbb51c..2f9c008d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: run: php ./tools/composer update --no-ansi --no-interaction --no-progress - name: Run tests with PHPUnit - run: ./vendor/bin/phpunit --log-junit test-results.xml --coverage-clover=code-coverage.xml + run: ./vendor/bin/phpunit --log-junit test-results.xml --coverage-openclover=code-coverage.xml - name: Upload test results to Codecov.io if: ${{ !cancelled() }} diff --git a/.phive/phars.xml b/.phive/phars.xml index 67ac0c7fa..dac7fc73f 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,5 +1,5 @@ - - + + diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 8780bbfb6..89883a868 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -17,12 +17,16 @@ $config = new PhpCsFixer\Config; $config->setFinder($finder) + ->setUnsupportedPhpVersionAllowed(true) ->setRiskyAllowed(true) ->setRules([ 'align_multiline_comment' => true, 'array_indentation' => true, 'array_push' => true, 'array_syntax' => ['syntax' => 'short'], + 'attribute_empty_parentheses' => [ + 'use_parentheses' => false, + ], 'backtick_to_shell_exec' => true, 'binary_operator_spaces' => [ 'operators' => [ diff --git a/ChangeLog-12.3.md b/ChangeLog-12.3.md index 4dbea8d21..f076381c5 100644 --- a/ChangeLog-12.3.md +++ b/ChangeLog-12.3.md @@ -2,6 +2,17 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [12.3.2] - 2025-07-29 + +### Changed + +* Add coverage and complexity columns to class and method complexity tables +* Add CRAP to graph tooltip + +### Fixed + +* [#1081](https://github.com/sebastianbergmann/php-code-coverage/issues/1081): Class complexity scatter chart tooltips show incorrect class + ## [12.3.1] - 2025-06-18 ### Changed @@ -15,5 +26,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * [#1080](https://github.com/sebastianbergmann/php-code-coverage/pull/1080): Support for reporting code coverage information in OpenClover XML format; unlike the existing Clover XML reporter, which remains unchanged, the XML documents generated by this new reporter validate against the OpenClover project's XML schema definition, with one exception: we do not generate the `` element. This feature is experimental and the generated XML might change in order to improve compliance with the OpenClover project's XML schema definition further. Such changes will be made in bugfix and/or minor releases even if they break backward compatibility. +[12.3.2]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.3.1...12.3.2 [12.3.1]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.3.0...12.3.1 [12.3.0]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.2.1...12.3.0 diff --git a/src/Report/Html/Renderer/Dashboard.php b/src/Report/Html/Renderer/Dashboard.php index 8a122a0a2..305c7fa10 100644 --- a/src/Report/Html/Renderer/Dashboard.php +++ b/src/Report/Html/Renderer/Dashboard.php @@ -10,7 +10,6 @@ namespace SebastianBergmann\CodeCoverage\Report\Html; use function array_values; -use function arsort; use function asort; use function assert; use function count; @@ -19,6 +18,8 @@ use function json_encode; use function sprintf; use function str_replace; +use function uasort; +use function usort; use SebastianBergmann\CodeCoverage\FileCouldNotBeWrittenException; use SebastianBergmann\CodeCoverage\Node\AbstractNode; use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode; @@ -105,6 +106,7 @@ private function complexity(array $classes, string $baseLink): array $method['ccn'], str_replace($baseLink, '', $method['link']), $methodName, + $method['crap'], ]; } @@ -113,9 +115,13 @@ private function complexity(array $classes, string $baseLink): array $class['ccn'], str_replace($baseLink, '', $class['link']), $className, + $class['crap'], ]; } + usort($result['class'], static fn (mixed $a, mixed $b) => ($a[0] <=> $b[0])); + usort($result['method'], static fn (mixed $a, mixed $b) => ($a[0] <=> $b[0])); + $class = json_encode($result['class']); assert($class !== false); @@ -276,37 +282,47 @@ private function projectRisks(array $classes, string $baseLink): array $key = $className . '::' . $methodName; } - $methodRisks[$key] = $method['crap']; + $methodRisks[$key] = $method; } } if ($class['coverage'] < $this->thresholds->highLowerBound() && $class['ccn'] > count($class['methods'])) { - $classRisks[$className] = $class['crap']; + $classRisks[$className] = $class; } } - arsort($classRisks); - arsort($methodRisks); + uasort($classRisks, static function (array $a, array $b) + { + return ((int) ($a['crap']) <=> (int) ($b['crap'])) * -1; + }); + uasort($methodRisks, static function (array $a, array $b) + { + return ((int) ($a['crap']) <=> (int) ($b['crap'])) * -1; + }); - foreach ($classRisks as $className => $crap) { + foreach ($classRisks as $className => $class) { $result['class'] .= sprintf( - ' %s%d' . "\n", + ' %s%.1f%%%d%d' . "\n", str_replace($baseLink, '', $classes[$className]['link']), $className, - $crap, + $class['coverage'], + $class['ccn'], + $class['crap'], ); } - foreach ($methodRisks as $methodName => $crap) { + foreach ($methodRisks as $methodName => $methodVals) { [$class, $method] = explode('::', $methodName); $result['method'] .= sprintf( - ' %s%d' . "\n", + ' %s%.1f%%%d%d' . "\n", str_replace($baseLink, '', $classes[$class]['methods'][$method]['link']), $methodName, $method, - $crap, + $methodVals['coverage'], + $methodVals['ccn'], + $methodVals['crap'], ); } diff --git a/src/Report/Html/Renderer/Template/dashboard.html.dist b/src/Report/Html/Renderer/Template/dashboard.html.dist index d7fb3b97a..d6575bc24 100644 --- a/src/Report/Html/Renderer/Template/dashboard.html.dist +++ b/src/Report/Html/Renderer/Template/dashboard.html.dist @@ -45,7 +45,7 @@
-

Insufficient Coverage

+

Insufficient Coverage

@@ -61,12 +61,14 @@
-

Project Risks

+

Project Risks

+ + @@ -79,7 +81,7 @@
-

Methods

+

Methods

@@ -98,7 +100,7 @@
-

Insufficient Coverage

+

Insufficient Coverage

ClassCoverageComplexity CRAP
@@ -114,12 +116,14 @@
-

Project Risks

+

Project Risks

+ + @@ -271,10 +275,12 @@ const coverage = Math.round(data[0].x); const complexity = data[0].value; const targetName = complexityData[data[0].index][3]; + const crap = complexityData[data[0].index][4]; return `
MethodCoverageComplexity CRAP
+
${targetName}
Coverage${coverage}%
Complexity${complexity}
Crap${crap}
`; }, grouped: false, diff --git a/src/Report/Html/Renderer/Template/dashboard_branch.html.dist b/src/Report/Html/Renderer/Template/dashboard_branch.html.dist index 80ac23243..eb003154a 100644 --- a/src/Report/Html/Renderer/Template/dashboard_branch.html.dist +++ b/src/Report/Html/Renderer/Template/dashboard_branch.html.dist @@ -45,7 +45,7 @@
-

Insufficient Coverage

+

Insufficient Coverage

@@ -61,7 +61,7 @@
-

Project Risks

+

Project Risks

@@ -79,7 +79,7 @@
-

Methods

+

Methods

@@ -98,7 +98,7 @@
-

Insufficient Coverage

+

Insufficient Coverage

@@ -114,7 +114,7 @@
-

Project Risks

+

Project Risks

diff --git a/src/StaticAnalysis/Visitor/AttributeParentConnectingVisitor.php b/src/StaticAnalysis/Visitor/AttributeParentConnectingVisitor.php index 3c87407e3..2e2141405 100644 --- a/src/StaticAnalysis/Visitor/AttributeParentConnectingVisitor.php +++ b/src/StaticAnalysis/Visitor/AttributeParentConnectingVisitor.php @@ -20,6 +20,8 @@ * * On the child node, the parent node can be accessed through * $node->getAttribute('parent'). + * + * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage */ final class AttributeParentConnectingVisitor implements NodeVisitor { diff --git a/src/Version.php b/src/Version.php index 69baec3e1..fe7c20d6c 100644 --- a/src/Version.php +++ b/src/Version.php @@ -19,7 +19,7 @@ final class Version public static function id(): string { if (self::$version === '') { - self::$version = (new VersionId('12.3.1', dirname(__DIR__)))->asString(); + self::$version = (new VersionId('12.3.2', dirname(__DIR__)))->asString(); } return self::$version; diff --git a/tests/_files/Report/HTML/CoverageForBankAccount/dashboard.html b/tests/_files/Report/HTML/CoverageForBankAccount/dashboard.html index a875e86ae..48a7ac744 100644 --- a/tests/_files/Report/HTML/CoverageForBankAccount/dashboard.html +++ b/tests/_files/Report/HTML/CoverageForBankAccount/dashboard.html @@ -47,7 +47,7 @@

Complexity

-

Insufficient Coverage

+

Insufficient Coverage

@@ -64,17 +64,19 @@

Insufficient Coverage

-

Project Risks

+

Project Risks

+ + - +
ClassCoverageComplexity CRAP
BankAccount6
BankAccount62.5%56
@@ -83,7 +85,7 @@

Project Risks

-

Methods

+

Methods

@@ -102,7 +104,7 @@

Complexity

-

Insufficient Coverage

+

Insufficient Coverage

@@ -119,17 +121,19 @@

Insufficient Coverage

-

Project Risks

+

Project Risks

+ + - +
MethodCoverageComplexity CRAP
setBalance6
setBalance0.0%26
@@ -144,8 +148,8 @@

Project Risks

- - + + - - + + - - + + - + - +