From 028221781452d212431122fccb2e433f55fac096 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 21 Dec 2023 10:21:08 +0100 Subject: [PATCH] Fix handling of throw statements when nikic/php-parser ^4.18 is used --- .../ExecutableLinesFindingVisitor.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php index 642991cf8..a13ad3eb4 100644 --- a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php +++ b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php @@ -116,6 +116,21 @@ 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);