Skip to content

Commit

Permalink
Support nikic/php-parser ^5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 21, 2023
1 parent c267817 commit 9bdd4a6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 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.11] - 2023-12-DD

### Changed

* This component is now compatible with `nikic/php-parser` 5.0

## [10.1.10] - 2023-12-11

### Fixed
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"sort-packages": true
},
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"php": ">=8.1",
"ext-dom": "*",
Expand Down
4 changes: 2 additions & 2 deletions src/StaticAnalysis/ExecutableLinesFindingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions src/StaticAnalysis/ParsingFileAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/StaticAnalysis/CodeUnitFindingVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 9bdd4a6

Please sign in to comment.