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

Update php parser to v5 #802

Open
wants to merge 7 commits into
base: next
Choose a base branch
from
Open

Conversation

vdauchy
Copy link

@vdauchy vdauchy commented Apr 27, 2024

Hi!

This is bigger than expected... it's basically just the update to PHP-Parser 5 (changelog: https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md) as I had conflicts with other dev dependencies.

There is a few changes(in the first commit) which change a lot of generated code (second commit).

For PHP-Parser the only added feature (kind of...) is the option php-version which target the parser and is used like this:

$parser = is_string($options['php-version'] ?? null)
            ? (new ParserFactory())->createForVersion(PhpVersion::fromString($options['php-version']))
            : (new ParserFactory())->createForHostVersion()
        ;

Most of the changes on the generated code are styles (function foo() : Bar changed to function foo(): Bar) and the use of Foo\Bar::class instead of Foo\\Bar string.

Now I need to try this out directly on my own projects using my fork, let me know what you think :-)

@Korbeil
Copy link
Member

Korbeil commented Apr 27, 2024

Hey @vdauchy ! Thanks for contributing !
We cannot make that upgrade like that, we would require something that can support either ^4 or ^5.
I know one of the latest v4 version of PHP Parser allows you to do that.

If you have any issues please ask I'll be glad to help 😃

@vdauchy
Copy link
Author

vdauchy commented Apr 27, 2024

Hi @Korbeil !

Thanks for answering, I updated everything to be compatible with the latest 4.x and ^5.0.
Locally 4.19 passes all tests.
However the 5.x do not due to:

  • The style of the return type (function foo() : Bar changed to function foo(): Bar)
  • The FQCN as string get some unescaping so I need to change that to Foo\Bar::class format.

image

If you have some idea for the styling I'm interested :-)

@vdauchy
Copy link
Author

vdauchy commented Apr 28, 2024

Quick follow up:

The only solution I see for the formatting issue with php-parser v5 is to add CS-Fixer as dev-depedency to composer and enable use-fixer=true.
This would change all existing snapshots, so it might be good to do it in a other PR (as it would be thousands of file changed just for styling) and this one is working for current PHP-Parser v4.

Any thoughts ?

I don't see any addition to do to this PR (but the styling following your advise), so let's me know if you need anything else to move forward :-)

@dkarlovi
Copy link
Contributor

Interestingly, this closes #760

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants