From 9bdd4a6b627cfdec91e02f7b378a3802c5015171 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 21 Dec 2023 09:45:19 +0100 Subject: [PATCH] Support nikic/php-parser ^5.0 --- ChangeLog-10.1.md | 7 +++++++ composer.json | 1 - src/StaticAnalysis/ExecutableLinesFindingVisitor.php | 4 ++-- src/StaticAnalysis/ParsingFileAnalyser.php | 6 +----- tests/tests/StaticAnalysis/CodeUnitFindingVisitorTest.php | 2 +- .../StaticAnalysis/ExecutableLinesFindingVisitorTest.php | 8 ++------ 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/ChangeLog-10.1.md b/ChangeLog-10.1.md index 62e3eae33..6d63dd260 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.11] - 2023-12-DD + +### Changed + +* This component is now compatible with `nikic/php-parser` 5.0 + ## [10.1.10] - 2023-12-11 ### Fixed @@ -77,6 +83,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.11]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.10...main [10.1.10]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.9...10.1.10 [10.1.9]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.8...10.1.9 [10.1.8]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.7...10.1.8 diff --git a/composer.json b/composer.json index dcb369e69..6e2ed05eb 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,6 @@ "sort-packages": true }, "prefer-stable": true, - "minimum-stability": "dev", "require": { "php": ">=8.1", "ext-dom": "*", diff --git a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php index 548243140..642991cf8 100644 --- a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php +++ b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php @@ -116,8 +116,8 @@ public function enterNode(Node $node): void return; } - if ($node instanceof Node\Stmt\Throw_) { - $this->setLineBranch($node->expr->getEndLine(), $node->expr->getEndLine(), ++$this->nextBranch); + 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; } diff --git a/src/StaticAnalysis/ParsingFileAnalyser.php b/src/StaticAnalysis/ParsingFileAnalyser.php index 3d1b5c886..3190bb4e1 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; @@ -140,10 +139,7 @@ private function analyse(string $filename): void assert($linesOfCode > 0); - $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 5042b222b..0f1a8c77b 100644 --- a/tests/tests/StaticAnalysis/CodeUnitFindingVisitorTest.php +++ b/tests/tests/StaticAnalysis/CodeUnitFindingVisitorTest.php @@ -144,7 +144,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 95491fe92..fcbd1075c 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 str_contains; -use PhpParser\Lexer; use PhpParser\NodeTraverser; use PhpParser\ParserFactory; use PHPUnit\Framework\Attributes\CoversClass; @@ -42,11 +41,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);