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

Upgrade to PHPParser 5 and PHPStan 2 #6431

Open
wants to merge 193 commits into
base: main
Choose a base branch
from

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Nov 14, 2024

Require patch branch of vendor-patches

Ref rectorphp/rector#8815

@samsonasik
Copy link
Member Author

samsonasik commented Nov 14, 2024

phpstan/phpdoc-parser seems needs to be upgraded to v2.0 as well to handle error undefined constant:

[ERROR] Could not process "rules/Php81/NodeFactory/EnumFactory.php" file, due  
         to:                                                                    
         "Undefined constant                                                    
         PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode::SINGLE_QUOTED".
         On line: 434        

ref https://github.com/phpstan/phpdoc-parser/blob/c00d78fb6b29658347f9d37ebe104bffadf36299/src/Ast/ConstExpr/ConstExprStringNode.php#L19

upgrading it currently got error:

There was 1 error:

1) Rector\Tests\Issues\DoubleRun\DoubleRunTest::test with data set #0 ('/Users/samsonasik/www/rector-...hp.inc')
Illuminate\Contracts\Container\BindingResolutionException: Unresolvable dependency resolving [Parameter #0 [ <required> array $usedAttributes ]] in class PHPStan\PhpDocParser\ParserConfig

will continue trying.

@samsonasik
Copy link
Member Author

Register ParserConfig as service seems handle it d301344

@staabm
Copy link
Contributor

staabm commented Nov 14, 2024

phpstan/phpdoc-parser seems needs to be upgraded to v2.0

Correct 👍

@samsonasik samsonasik force-pushed the upgrade-to-php-parser5-and-phpstan-2 branch 4 times, most recently from 6992147 to c183f3c Compare November 15, 2024 12:16
@samsonasik
Copy link
Member Author

PHPStan RichParser seems cause error on read curly array: $string{0}

There was 1 error:

1) Rector\Tests\Php74\Rector\ArrayDimFetch\CurlyToSquareBracketArrayStringRector\CurlyToSquareBracketArrayStringRectorTest::test with data set #0 ('/Users/samsonasik/www/rector-...hp.inc')
PHPStan\Parser\ParserErrorsException: Syntax error, unexpected '{', expecting ';', Syntax error, unexpected '{', expecting ';', Syntax error, unexpected '{', expecting ';'

phar:///Users/samsonasik/www/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Parser/RichParser.php:70

I will try if it possible to use native PHPParser Parser.

@samsonasik
Copy link
Member Author

use simple parser for defaultAnalysisParser, with native parser php 7.0 469b596

Before

There was 1 error:

1) Rector\Tests\Php74\Rector\ArrayDimFetch\CurlyToSquareBracketArrayStringRector\CurlyToSquareBracketArrayStringRectorTest::test with data set #0 ('/Users/samsonasik/www/rector-...hp.inc')
PHPStan\Parser\ParserErrorsException: Syntax error, unexpected '{', expecting ';', Syntax error, unexpected '{', expecting ';', Syntax error, unexpected '{', expecting ';'

phar:///Users/samsonasik/www/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Parser/RichParser.php:70

After

➜  rector-src git:(upgrade-to-php-parser5-and-phpstan-2) ✗ vendor/bin/phpunit rules-tests/Php74/Rector/ArrayDimFetch/CurlyToSquareBracketArrayStringRector/CurlyToSquareBracketArrayStringRectorTest.php --filter=#0
PHPUnit 10.5.38 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.12
Configuration: /Users/samsonasik/www/rector-src/phpunit.xml

.                                                                   1 / 1 (100%)

Time: 00:00.316, Memory: 62.50 MB

OK (1 test, 2 assertions)

This needs to fallback to php 8.0 feature as well, I will continue :)

@samsonasik samsonasik force-pushed the upgrade-to-php-parser5-and-phpstan-2 branch 4 times, most recently from 6acb52e to 3bb03c6 Compare November 17, 2024 03:01
@samsonasik
Copy link
Member Author

I got it, using ->createForNewestSupportedVersion() is fine to be on default, then if it catch PHPStan\Parser\ParserErrorsException, fallback to use php 7 parser when doing parsing, see 3bb03c6

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.

3 participants