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

PHP-Parser v.5.x dependency leads to errors in tombstone-analyzer #33

Closed
fbecker-complex opened this issue Jan 30, 2025 · 2 comments
Closed
Labels

Comments

@fbecker-complex
Copy link
Contributor

Package version: 1.7.0

Description
I tried to use the tombstone-analyzer and got the following error: Call to undefined method PhpParser\ParserFactory::create()
While investigating I found that the tombstone-analyzer allows nikic/php-parser in the versions ^4.0|^5.0, but the ParceFactory::create()-Method was removed in version 5.0.0

Unfortunately I need the php-parser in a version ^5.1, so I can't just use ^4.

To Reproduce

  1. composer require --dev phpstan/phpstan-webmozart-assert
  2. composer require scheb/tombstone-logger
  3. composer require scheb/tombstone-analyzer --dev
  4. Add a basic setup
  5. Try running vendor/bin/tombstone-analyzer

Possible Solution
Could you adjust your code, to also work for php-parser ^5.0 ?
After a quick test, it looks like it could be as simple as adjusting the ParserTombstoneProvider::create()-function as follows:

// OLD:
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new Lexer());

// NEW:
 if (method_exists(ParserFactory::class, 'create')) {
     $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new Lexer());
else {
    $parser = (new ParserFactory())->createForVersion(PhpVersion::getHostVersion());
}
@scheb
Copy link
Owner

scheb commented Jan 31, 2025

That was likely changed at some point within the v5. Feel free to send in a PR with a fix.

@fbecker-complex
Copy link
Contributor Author

That was likely changed at some point within the v5. Feel free to send in a PR with a fix.

Thanks for the quick reply.
I created a PR with the quick fix from above: #35
Please take a look at it and let me know if that works for you

@scheb scheb closed this as completed Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants