phpro / grumphp

A PHP code-quality tool
MIT License
4.11k stars 429 forks source link

Undefined constant PhpParser\ParserFactory::PREFER_PHP7 when using `nikic/php-parser` version 5. #1119

Closed dxvargas closed 4 months ago

dxvargas commented 5 months ago
Q A
Version master
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets PR #218

The composer dependency for nikic/php-parser is only a dev dependency and it's set now to "^4.13" Now this package has a new version 5.

This version 5 is not using PREFER_PHP7 anymore as stated in the upgrade docs.

The current code in grumphp is using the code in nikic/php-parse. See here: https://github.com/phpro/grumphp/blob/v2.4.0/src/Parser/Php/Factory/ParserFactory.php

Now running grumphp results in this error:

Running task 1/1: phpparser... ✘

Undefined constant PhpParser\ParserFactory::PREFER_PHP7

So, the ParserFactory here needs changes to work with nikic/php-parse version 5.

I'm not sure but I'm considering it a bug because the dependency for nikic/php-parse allows the usage of version 5 but it doesn't work. If it was not a dev dependecy, we wouldn't have errors, because it's set to version 4 there.

veewee commented 5 months ago

You are correct. The parser task hasn't been tested against version 5 of nikic's phpparser so it probably won't work out of the box without it getting additional love.

I'm a bit in doubt about deprecating the task though: with static analysis tools like psalm and phpstan, there are better options for doing the same checks - without us having to maintain this inside grumphp's repo.

Another option could be to extract the logic into a new minimalistic analysis tool that can be maintained in that separate repository.

All feedback is welcome so that we can make valid decisions regarding the parser task. In the meantime, I accept PRs that make grumphp compatible with V5.