diff --git a/ChangeLog-10.1.md b/ChangeLog-10.1.md index 95588dcd5..621971a88 100644 --- a/ChangeLog-10.1.md +++ b/ChangeLog-10.1.md @@ -2,6 +2,12 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [10.1.15] - 2024-MM-DD + +### Fixed + +* [#967](https://github.com/sebastianbergmann/php-code-coverage/issues/967): Identification of executable lines for `match` expressions does not work correctly + ## [10.1.14] - 2024-03-12 ### Fixed @@ -101,6 +107,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * The `SebastianBergmann\CodeCoverage\Filter::includeDirectory()`, `SebastianBergmann\CodeCoverage\Filter::excludeDirectory()`, and `SebastianBergmann\CodeCoverage\Filter::excludeFile()` methods are now deprecated +[10.1.15]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.14...10.1 [10.1.14]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.13...10.1.14 [10.1.13]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.12...10.1.13 [10.1.12]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.11...10.1.12 diff --git a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php index f0e8d72b5..a15894da3 100644 --- a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php +++ b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php @@ -105,7 +105,6 @@ public function enterNode(Node $node): void $node instanceof Node\Stmt\Use_ || $node instanceof Node\Stmt\UseUse || $node instanceof Node\Expr\ConstFetch || - $node instanceof Node\Expr\Match_ || $node instanceof Node\Expr\Variable || $node instanceof Node\Expr\Throw_ || $node instanceof Node\ComplexType || @@ -117,6 +116,18 @@ public function enterNode(Node $node): void return; } + if ($node instanceof Node\Expr\Match_) { + foreach ($node->arms as $arm) { + $this->setLineBranch( + $arm->body->getStartLine(), + $arm->body->getEndLine(), + ++$this->nextBranch, + ); + } + + return; + } + /* * nikic/php-parser ^4.18 represents throw statements * as Stmt\Throw_ objects diff --git a/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php b/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php index a9b776861..f65010b01 100644 --- a/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php +++ b/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php @@ -9,7 +9,6 @@ */ namespace SebastianBergmann\CodeCoverage\StaticAnalysis; -use PHPUnit\Framework\Attributes\Ticket; use function explode; use function file_get_contents; use function preg_match; @@ -18,6 +17,7 @@ use PhpParser\ParserFactory; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhp; +use PHPUnit\Framework\Attributes\Ticket; use PHPUnit\Framework\TestCase; #[CoversClass(ExecutableLinesFindingVisitor::class)]