Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow phpParser in version ^5.0 #35

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/analyzer/Stock/ParserTombstoneProvider.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 Scheb\Tombstone\Analyzer\Cli\ConsoleOutputInterface;
use Scheb\Tombstone\Core\FinderFacade;
use Scheb\Tombstone\Core\Model\RootPath;
Expand Down Expand Up @@ -38,7 +39,13 @@
public static function create(array $config, ConsoleOutputInterface $consoleOutput): TombstoneProviderInterface
{
$sourceRootPath = new RootPath($config['source_code']['root_directory']);
$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());

Check failure on line 45 in src/analyzer/Stock/ParserTombstoneProvider.php

View workflow job for this annotation

GitHub Actions / Coding Standards - PHP 8.3

UndefinedClass

src/analyzer/Stock/ParserTombstoneProvider.php:45:63: UndefinedClass: Class, interface or enum named PhpParser\PhpVersion does not exist (see https://psalm.dev/019)
} else {
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new Lexer());
}
$traverser = new NodeTraverser();
$extractor = new TombstoneExtractor($parser, $traverser, $sourceRootPath);
$traverser->addVisitor(new TombstoneNodeVisitor($extractor, $config['tombstones']['parser']['function_names']));
Expand Down
Loading