-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
Conversation
upgrading it currently got error:
will continue trying. |
Register |
Correct 👍 |
6992147
to
c183f3c
Compare
PHPStan RichParser seems cause error on read curly array:
I will try if it possible to use native PHPParser Parser. |
use simple parser for defaultAnalysisParser, with native parser php 7.0 469b596 Before
After
This needs to fallback to php 8.0 feature as well, I will continue :) |
6acb52e
to
3bb03c6
Compare
I got it, using |
632553a
to
f381808
Compare
@TomasVotruba this is so far so good :), the todo is Doctrine annotation detection, which bc break on phpstan/phpdoc-parser 2, I will continue :) |
@TomasVotruba a first step progress on doctrine annotation 🎉 , it needs detect class name from Before There was 1 failure:
1) Rector\Tests\Issues\FqcnAnnotationToAttribute\FqcnAnnotationToAttributeTest::test with data set #3 ('/Users/samsonasik/www/rector-...hp.inc')
Failed on fixture file "sub_namespace_from_use.php.inc"
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
use Doctrine\ORM\Mapping;
-#[Mapping\Entity]
+/**
+ * @Mapping\Entity()
+ */
class SubNamespaceFromUse
{
} After
|
All checks have passed 🎉 @TomasVotruba I think it is ready 🎉 🎉 🎉 |
Let's ship it, so we can iterate faster 👍 Thanks for pushing this forwards @samsonasik 💪 |
@TomasVotruba thank you for the merge, I will fix the downgrade notice :) https://github.com/rectorphp/rector-src/actions/runs/11936299874/job/33269627769#step:10:20 |
Just one error on downgrade:
I will check |
Downgrade succeed 🎉 Now, goes to fix php 7 code notice e2e test on rector/rector: class Foo
{
public function __construct()
{
$bar = 'baz';
print $bar{2};
}
} https://github.com/rectorphp/rector/actions/runs/11937063227/job/33272177173#step:5:13 |
Ok, it seems the issue is on downgrade process, the token got array over Token object: ➜ rector-src git:(main) ✗ bin/rector process vendor/nikic/php-parser/lib/PhpParser/Lexer.php --config build/config/config-downgrade.php --dry-run --clear-cache
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
1 file with changes
===================
1) vendor/nikic/php-parser/lib/PhpParser/Lexer.php:27
---------- begin diff ----------
@@ @@
$scream = ini_set('xdebug.scream', '0');
- $tokens = @Token::tokenize($code);
+ $tokens = @token_get_all($code);
$this->postprocessTokens($tokens, $errorHandler);
if (false !== $scream) {
@@ @@
}
private function handleInvalidCharacter(Token $token, ErrorHandler $errorHandler): void {
- $chr = $token->text;
+ $chr = is_array($token) ? $token[1] : $token;
if ($chr === "\0") {
// PHP cuts error message after null byte, so need special case
$errorMsg = 'Unexpected null byte';
@@ @@
private function isUnterminatedComment(Token $token): bool {
return $token->is([\T_COMMENT, \T_DOC_COMMENT])
- && substr($token->text, 0, 2) === '/*'
- && substr($token->text, -2) !== '*/';
+ && substr(is_array($token) ? $token[1] : $token, 0, 2) === '/*'
+ && substr(is_array($token) ? $token[1] : $token, -2) !== '*/';
}
/**
@@ @@
for ($i = 0; $i < $numTokens; $i++) {
$token = $tokens[$i];
- if ($token->id === \T_BAD_CHARACTER) {
+ if ((is_array($token) ? $token[0] : $token) === \T_BAD_CHARACTER) {
$this->handleInvalidCharacter($token, $errorHandler);
}
- if ($token->id === \ord('&')) {
+ if ((is_array($token) ? $token[0] : $token) === \ord('&')) {
$next = $i + 1;
- while (isset($tokens[$next]) && $tokens[$next]->id === \T_WHITESPACE) {
+ while (isset($tokens[$next]) && (is_array($tokens[$next]) ? $tokens[$next][0] : $tokens[$next]) === \T_WHITESPACE) {
$next++;
}
$followedByVarOrVarArg = isset($tokens[$next]) &&
$tokens[$next]->is([\T_VARIABLE, \T_ELLIPSIS]);
- $token->id = $followedByVarOrVarArg
+ is_array($token) ? $token[0] : $token = $followedByVarOrVarArg
? \T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG
: \T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG;
}
----------- end diff -----------
Applied rules:
* DowngradePhpTokenRector I will continue checking... |
it seems php-parser internal Token polyfill needs to be skipped |
@TomasVotruba Finally 🎉 🎉 🎉 All green 🎉 🎉 🎉 |
Require patch branch of vendor-patches
Ref rectorphp/rector#8815