-
-
Notifications
You must be signed in to change notification settings - Fork 365
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
Fix issue of parsing PHP 8 sources on PHP 7.x #1184
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ondrejmirtes I confirm that it works 🎉 Thank you
Awesome, thank you 👏 |
Related bug: rectorphp/rector#6799 We'll need 2 parsers:
|
@ondrejmirtes Any ideas how to make those 2 parser like PHPStan has? I'm trying to play with neon syntax, but I keep failing as I never used it without autowiring. |
@TomasVotruba You need a PathRoutingParser like PHPStan has (/~https://github.com/phpstan/phpstan-src/blob/master/src/Parser/PathRoutingParser.php), but probably not exactly the same one, but custom for your needs. This is how it's configured: /~https://github.com/phpstan/phpstan-src/blob/ce0b04308d4761f6efd8ce3fec90be59e1197ced/conf/config.neon#L1744-L1750 |
Not sure how to configure it and how that would help. So far I think the problem is the default parser is used for stubs that are in PHP 8. |
That's exactly how PathRoutingParser can help you. |
Any ideas how exacly it should be configured? What does "path routing" mean? This parses PHP 7.4 code, but fails to parse stubs: #parameters:
# phpVersion: 80100
services:
defaultAnalysisParser:
factory: @cachedRectorParser
arguments!: []
cachedRectorParser:
class: PHPStan\Parser\CachedParser
arguments:
originalParser: @rectorParser
cachedNodesByStringCountMax: %cache.nodesByStringCountMax%
autowired: no
rectorParser:
class: PHPStan\Parser\RichParser
arguments:
parser: @currentPhpVersionPhpParser
lexer: @currentPhpVersionLexer
autowired: no
pathRoutingParser:
class: PHPStan\Parser\PathRoutingParser
arguments:
currentPhpVersionRichParser: @php8PhpParser
currentPhpVersionSimpleParser: @php8PhpParser
php8Parser: @php8Parser
autowired: false |
This calls for a phone call again :) I have time on Friday. |
It fails on But it seems Nette DI is unable to override anonymous services :/ -
class: PHPStan\Type\FileTypeMapper
arguments:
- phpParser: @defaultAnalysisParser
+ phpParser: @pathRoutingParser ↓ PHP Fatal error: Uncaught _PHPStan_c862bb974\Nette\DI\ServiceCreationException:
Multiple services of type PHPStan\Type\FileTypeMapper found: 0114, 0246 in phar:///var/www/rector-syntax-bug/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/nette/di/src/DI/Autowiring.php:53 |
The |
I'd prefer to solve it now :D it seems extreemely hard for such a simple task. |
Something like this? services:
pathRoutingParser:
class: PHPStan\Parser\PathRoutingParser
arguments:
currentPhpVersionRichParser: @rectorParser
currentPhpVersionSimpleParser: @rectorParser
php8Parser: @php8Parser
autowired: false
rectorParser:
class: PHPStan\Parser\RichParser
arguments:
parser: @currentPhpVersionPhpParser
lexer: @currentPhpVersionLexer
autowired: no |
I'd prefer if you wrote your own PathRoutingParser, the one from PHPStan is too complex and unsuitable for your needs. You also need to include:
|
If I understand what it does and why, I'll try 👍 It looks that this - #1184 (comment) - works for both fixture and CI in this repository.
I'll try |
The work is done in #1480 |
Looks good, the tests pass here, the repository with bug is fixed too: /~https://github.com/cjunge-work/rector-syntax-bug/pull/3 Thanks @ondrejmirtes 👍 👏 I can sleep in peace today :) |
Thank you @TomasVotruba!!! 🍻 |
This fixes rectorphp/rector#6779
/cc @samsonasik @TomasVotruba