diff --git a/ChangeLog-9.2.md b/ChangeLog-9.2.md
index a2c343316..47db87388 100644
--- a/ChangeLog-9.2.md
+++ b/ChangeLog-9.2.md
@@ -2,6 +2,12 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
+## [9.2.30] - 2023-12-DD
+
+### Changed
+
+* This component is now compatible with `nikic/php-parser` 5.0
+
## [9.2.29] - 2023-09-19
### Fixed
@@ -499,6 +505,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* This component is no longer supported on PHP 7.1
+[9.2.30]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.29...9.2
[9.2.29]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.28...9.2.29
[9.2.28]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.27...9.2.28
[9.2.27]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.26...9.2.27
diff --git a/composer.json b/composer.json
index d802995b5..3646210fe 100644
--- a/composer.json
+++ b/composer.json
@@ -28,7 +28,6 @@
"sort-packages": true
},
"prefer-stable": true,
- "minimum-stability": "dev",
"require": {
"php": ">=7.3",
"ext-dom": "*",
diff --git a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php
index eadff1cf0..38e64c0b0 100644
--- a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php
+++ b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php
@@ -112,6 +112,7 @@ public function enterNode(Node $node): void
$node instanceof Node\Expr\ConstFetch ||
$node instanceof Node\Expr\Match_ ||
$node instanceof Node\Expr\Variable ||
+ $node instanceof Node\Expr\Throw_ ||
$node instanceof Node\ComplexType ||
$node instanceof Node\Const_ ||
$node instanceof Node\Identifier ||
@@ -121,12 +122,27 @@ public function enterNode(Node $node): void
return;
}
+ /*
+ * nikic/php-parser ^4.18 represents throw
statements
+ * as Stmt\Throw_
objects
+ */
if ($node instanceof Node\Stmt\Throw_) {
$this->setLineBranch($node->expr->getEndLine(), $node->expr->getEndLine(), ++$this->nextBranch);
return;
}
+ /*
+ * nikic/php-parser ^5 represents throw
statements
+ * as Stmt\Expression
objects that contain an
+ * Expr\Throw_
object
+ */
+ if ($node instanceof Node\Stmt\Expression && $node->expr instanceof Node\Expr\Throw_) {
+ $this->setLineBranch($node->expr->expr->getEndLine(), $node->expr->expr->getEndLine(), ++$this->nextBranch);
+
+ return;
+ }
+
if ($node instanceof Node\Stmt\Enum_ ||
$node instanceof Node\Stmt\Function_ ||
$node instanceof Node\Stmt\Class_ ||
diff --git a/src/StaticAnalysis/ParsingFileAnalyser.php b/src/StaticAnalysis/ParsingFileAnalyser.php
index e68638219..923b1f50f 100644
--- a/src/StaticAnalysis/ParsingFileAnalyser.php
+++ b/src/StaticAnalysis/ParsingFileAnalyser.php
@@ -22,7 +22,6 @@
use function token_get_all;
use function trim;
use PhpParser\Error;
-use PhpParser\Lexer;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\NodeVisitor\ParentConnectingVisitor;
@@ -142,10 +141,7 @@ private function analyse(string $filename): void
$linesOfCode = 1;
}
- $parser = (new ParserFactory)->create(
- ParserFactory::PREFER_PHP7,
- new Lexer
- );
+ $parser = (new ParserFactory)->createForHostVersion();
try {
$nodes = $parser->parse($source);
diff --git a/tests/tests/StaticAnalysis/CodeUnitFindingVisitorTest.php b/tests/tests/StaticAnalysis/CodeUnitFindingVisitorTest.php
index e9a6a6d10..c1495404e 100644
--- a/tests/tests/StaticAnalysis/CodeUnitFindingVisitorTest.php
+++ b/tests/tests/StaticAnalysis/CodeUnitFindingVisitorTest.php
@@ -148,7 +148,7 @@ public function testHandlesFunctionOrMethodWithDisjunctiveNormalFormTypes(): voi
private function findCodeUnits(string $filename): CodeUnitFindingVisitor
{
- $nodes = (new ParserFactory)->create(ParserFactory::PREFER_PHP7)->parse(
+ $nodes = (new ParserFactory)->createForHostVersion()->parse(
file_get_contents($filename)
);
diff --git a/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php b/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php
index c9089a45e..aa71d035b 100644
--- a/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php
+++ b/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php
@@ -13,7 +13,6 @@
use function file_get_contents;
use function preg_match;
use function strpos;
-use PhpParser\Lexer;
use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;
use PHPUnit\Framework\TestCase;
@@ -62,11 +61,8 @@ public function testExecutableLinesAreGroupedByBranchPhp82(): void
private function doTestSelfDescribingAsset(string $filename): void
{
- $source = file_get_contents($filename);
- $parser = (new ParserFactory)->create(
- ParserFactory::PREFER_PHP7,
- new Lexer
- );
+ $source = file_get_contents($filename);
+ $parser = (new ParserFactory)->createForHostVersion();
$nodes = $parser->parse($source);
$executableLinesFindingVisitor = new ExecutableLinesFindingVisitor($source);