rector icon indicating copy to clipboard operation
rector copied to clipboard

Plan to upgrade to PHP-Parser 5.0

Open ondrejmirtes opened this issue 3 years ago • 4 comments

Question

As of today there's alpha 1 of nikic/php-parser 5.0. PHP-Parser is the single most important foundation building block of PHPStan which Rector is dependent upon.

I wrote my thoughts and plans about upgrading PHPStan to PHP-Parser 5.0: https://github.com/phpstan/phpstan/issues/7943

Can you please check them out and let me know if you agree with them? I'd like to make sure you're happy with this plan and you can wait with the upgrade to PHP-Parser 5.0 until PHPStan 2.0 is out.

Thanks.

ondrejmirtes avatar Sep 06 '22 09:09 ondrejmirtes

Hi Ondra, thanks for asking. I'm thinking about this last week and even more, after I saw you're testing it in PHPStan :)

Befor reading the issue, I'll share the conventions we have. We upgrade to a newer version of our dependencies as possible for 3 reasons:

  • it's cheap and fast, as we already have the new api of the package in attention - e.g. upgrading to php-parser 5 in a year would be look of history googling, how the things are done
  • we're gonna make a php-parser 5 upgrade set anyway as soon as possible, to make the other 1200 projects using it no brianer to upgrade
  • in particular of php-parser, there is lot of printer fixes that we hack around now in a dirty regex way, and we want to drop these hacks for native clean support

I went through the linked issue and these are my thoughts:

  • the version bump on php-parser bump makes sense; we'd do the same here, maybe even going to Rector 1.0
  • it depends when the stable php-parser version is going to be released
  • the "not extending Expr anymore" can be easily fixed with patches - we already add custom StmtsAwareInterface to make writing rules easier - https://github.com/rectorphp/vendor-patches/tree/main/patches
  • it also depends when we have free time to make the upgrade set

I didn't go through the php-parser changes in detail yet, but if the node renames and extends are the only issues, the upgrade should be straightforward.

So no rush on PHPStan side, we'll prepare the upgrade set for community and when we're both ready, we can go together :)

TomasVotruba avatar Sep 06 '22 12:09 TomasVotruba

Ref https://github.com/rectorphp/rector-src/pull/2916 for starter

samsonasik avatar Sep 07 '22 02:09 samsonasik

RenameClassRector seems can be used for Node names movement, for example, for ArrayItem ref https://getrector.org/demo/70ad3d97-671c-435f-9bc4-dd37b1b57874

Configurable config set for that can be added to https://github.com/rectorphp/rector-php-parser

samsonasik avatar Sep 07 '22 03:09 samsonasik

@ondrejmirtes @TomasVotruba I start adding rector set list for upgrade deprecated class to php-parser 5.0 https://github.com/rectorphp/rector-php-parser/pull/2

samsonasik avatar Sep 17 '22 06:09 samsonasik

php-parser 5.0.0-alpha2 released https://github.com/nikic/PHP-Parser/releases/tag/v5.0.0alpha2

samsonasik avatar Mar 05 '23 12:03 samsonasik

It might take years after php-parser 5.0 is released, as it's API is not prefixed. Closing as this is not in our focus now.

Let's reopen when this becomes a valuable feature for Rector users :)

TomasVotruba avatar May 13 '23 13:05 TomasVotruba