Skip to content

Commit 9bdd4a6

Browse files
Support nikic/php-parser ^5.0
1 parent c267817 commit 9bdd4a6

6 files changed

+13
-15
lines changed

ChangeLog-10.1.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
44

5+
## [10.1.11] - 2023-12-DD
6+
7+
### Changed
8+
9+
* This component is now compatible with `nikic/php-parser` 5.0
10+
511
## [10.1.10] - 2023-12-11
612

713
### Fixed
@@ -77,6 +83,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
7783

7884
* The `SebastianBergmann\CodeCoverage\Filter::includeDirectory()`, `SebastianBergmann\CodeCoverage\Filter::excludeDirectory()`, and `SebastianBergmann\CodeCoverage\Filter::excludeFile()` methods are now deprecated
7985

86+
[10.1.11]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.10...main
8087
[10.1.10]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.9...10.1.10
8188
[10.1.9]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.8...10.1.9
8289
[10.1.8]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.7...10.1.8

composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"sort-packages": true
2929
},
3030
"prefer-stable": true,
31-
"minimum-stability": "dev",
3231
"require": {
3332
"php": ">=8.1",
3433
"ext-dom": "*",

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public function enterNode(Node $node): void
116116
return;
117117
}
118118

119-
if ($node instanceof Node\Stmt\Throw_) {
120-
$this->setLineBranch($node->expr->getEndLine(), $node->expr->getEndLine(), ++$this->nextBranch);
119+
if ($node instanceof Node\Stmt\Expression && $node->expr instanceof Node\Expr\Throw_) {
120+
$this->setLineBranch($node->expr->expr->getEndLine(), $node->expr->expr->getEndLine(), ++$this->nextBranch);
121121

122122
return;
123123
}

src/StaticAnalysis/ParsingFileAnalyser.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use function token_get_all;
2323
use function trim;
2424
use PhpParser\Error;
25-
use PhpParser\Lexer;
2625
use PhpParser\NodeTraverser;
2726
use PhpParser\NodeVisitor\NameResolver;
2827
use PhpParser\NodeVisitor\ParentConnectingVisitor;
@@ -140,10 +139,7 @@ private function analyse(string $filename): void
140139

141140
assert($linesOfCode > 0);
142141

143-
$parser = (new ParserFactory)->create(
144-
ParserFactory::PREFER_PHP7,
145-
new Lexer
146-
);
142+
$parser = (new ParserFactory)->createForHostVersion();
147143

148144
try {
149145
$nodes = $parser->parse($source);

tests/tests/StaticAnalysis/CodeUnitFindingVisitorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function testHandlesFunctionOrMethodWithDisjunctiveNormalFormTypes(): voi
144144

145145
private function findCodeUnits(string $filename): CodeUnitFindingVisitor
146146
{
147-
$nodes = (new ParserFactory)->create(ParserFactory::PREFER_PHP7)->parse(
147+
$nodes = (new ParserFactory)->createForHostVersion()->parse(
148148
file_get_contents($filename)
149149
);
150150

tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use function file_get_contents;
1414
use function preg_match;
1515
use function str_contains;
16-
use PhpParser\Lexer;
1716
use PhpParser\NodeTraverser;
1817
use PhpParser\ParserFactory;
1918
use PHPUnit\Framework\Attributes\CoversClass;
@@ -42,11 +41,8 @@ public function testExecutableLinesAreGroupedByBranchPhp82(): void
4241

4342
private function doTestSelfDescribingAsset(string $filename): void
4443
{
45-
$source = file_get_contents($filename);
46-
$parser = (new ParserFactory)->create(
47-
ParserFactory::PREFER_PHP7,
48-
new Lexer
49-
);
44+
$source = file_get_contents($filename);
45+
$parser = (new ParserFactory)->createForHostVersion();
5046
$nodes = $parser->parse($source);
5147
$executableLinesFindingVisitor = new ExecutableLinesFindingVisitor($source);
5248

0 commit comments

Comments
 (0)