Skip to content

Commit

Permalink
Closes #967
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 29, 2024
1 parent 9b0a889 commit 09c0fda
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-10.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/StaticAnalysis/ExecutableLinesFindingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand All @@ -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 <code>throw</code> statements
* as <code>Stmt\Throw_</code> objects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand Down

0 comments on commit 09c0fda

Please sign in to comment.