Skip to content

Commit

Permalink
Condition for php-parser v5
Browse files Browse the repository at this point in the history
  • Loading branch information
scheb committed Feb 4, 2025
1 parent 4eafa1c commit b8cab56
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/Analyzer/Stock/TombstoneExtractorIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Lexer;
use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;
use PhpParser\PhpVersion;
use PHPUnit\Framework\MockObject\MockObject;
use Scheb\Tombstone\Analyzer\Stock\TombstoneExtractor;
use Scheb\Tombstone\Analyzer\Stock\TombstoneNodeVisitor;
Expand Down Expand Up @@ -36,7 +37,13 @@ protected function setUp(): void
->method('createFilePath')
->willReturn($this->filePath);

$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new Lexer());
// This if enables nikic/php-parser in version ^5.0. The ‘create’ function no longer exists here.
if (method_exists(ParserFactory::class, 'createForVersion')) {
$parser = (new ParserFactory())->createForVersion(PhpVersion::getHostVersion());
} else {
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new Lexer());
}

$traverser = new NodeTraverser();
$this->extractor = new TombstoneExtractor($parser, $traverser, $sourceRootPath);
$traverser->addVisitor(new TombstoneNodeVisitor($this->extractor, [
Expand Down

0 comments on commit b8cab56

Please sign in to comment.