Skip to content

[ProcessAnalyzer] Skip process when origNode class is not equal with target node class#4861

Merged
samsonasik merged 5 commits intomainfrom
ksip
Aug 27, 2023
Merged

[ProcessAnalyzer] Skip process when origNode class is not equal with target node class#4861
samsonasik merged 5 commits intomainfrom
ksip

Conversation

@samsonasik
Copy link
Copy Markdown
Member

@TomasVotruba I tried locally, and verify origNode is equal with target $node class early on reprint seems fix the downgrade issue.

Ref #4841 (review)

Let's give it a try and test enable downgrade vendor/rector/rector-*/config again.

@samsonasik samsonasik marked this pull request as draft August 27, 2023 06:46
@samsonasik
Copy link
Copy Markdown
Member Author

The issue seems sowewhere deeper on traversing, so it seems not working...

@samsonasik
Copy link
Copy Markdown
Member Author

@TomasVotruba ok, I am debugging, so to make $node somehow know its position, the $node need to by debug:

d($node);
PhpParser\Node\Expr\ClassConstFetch #42595
   class: PhpParser\Node\Name\FullyQualified #42230
   |  parts: array (4) ...
   |  attributes: array (11) ...
   name: PhpParser\Node\Identifier #62762
   |  name: 'UP_TO_TWIG_134'
   |  attributes: array (10) ...
   attributes: array (12)
   |  'startLine' => 10
   |  'startTokenPos' => 52
   |  'startFilePos' => 251
   |  'endLine' => 10
   |  'endTokenPos' => 54
   |  'endFilePos' => 282
   |  'statementOrder' => 0
   |  'statementDepth' => 2
   |  'expressionOrder' => 0
   |  'expressionDepth' => 4
   |  'scope' => PHPStan\Analyser\MutatingScope #42283 ...
   |  'origNode' => PhpParser\Node\Expr\ClassConstFetch #42320 ...

 69/69 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
                                                                                                                        
 [OK] 6 files would have changed (dry-run) by Rector                                                                    
                                                                                                                        

so, it possibly memory on hold got loss when debug enabled.

@samsonasik
Copy link
Copy Markdown
Member Author

@TomasVotruba give me time....

@samsonasik
Copy link
Copy Markdown
Member Author

I tried to extract downgrade lists and it seems the issue is when import:

$rectorConfig->import(DowngradeSetList::PHP_73);

so somewhere in that rules...

@samsonasik
Copy link
Copy Markdown
Member Author

@TomasVotruba ok, the bug seems on DowngradeTrailingCommasInFunctionCallsRector, I will look into it ;)

Comment on lines +231 to +241
$result = $this->nodesToReturn[$objectHash] ?? $node;

if (is_array($result)) {
return $result;
}

if ($result::class === $node::class) {
return $result;
}

return $node;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasVotruba it seems the tweak 👍

Before

➜  rector-src git:(ksip) bin/rector process vendor/rector/rector-symfony/config/sets --config build/config/config-downgrade.php --ansi --dry-run --clear-cache --no-diffs
 69/69 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
                                                                                                                        
 [ERROR] Could not process                                                                                              
         "/Users/samsonasik/www/rector-src/vendor/rector/rector-symfony/config/sets/twig/level/up-to-twig-127.php" file,
         due to:                                                                                                        
         "System error: "Trying to replace statement (Stmt_Return) with expression (Expr_MethodCall). Are you missing a 
         Stmt_Expression wrapper?"                                                                                      
         Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On line: 277

After

➜  rector-src git:(ksip) ✗ bin/rector process vendor/rector/rector-symfony/config/sets --config build/config/config-downgrade.php --ansi --dry-run --clear-cache --no-diffs
 69/69 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
                                                                                                                        
 [OK] 6 files would have changed (dry-run) by Rector                                                                    
                                                                                                                        

@samsonasik samsonasik marked this pull request as ready for review August 27, 2023 13:23
@samsonasik
Copy link
Copy Markdown
Member Author

All checks have passed 🎉 @TomasVotruba let's give it a try 👍

@samsonasik samsonasik merged commit 3199e0a into main Aug 27, 2023
@samsonasik samsonasik deleted the ksip branch August 27, 2023 13:23
@samsonasik
Copy link
Copy Markdown
Member Author

@TomasVotruba it works 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉

Screen Shot 2023-08-27 at 20 26 43

@TomasVotruba
Copy link
Copy Markdown
Member

TomasVotruba commented Aug 27, 2023

Thank you 🤗 what a journey to follow your work 👏 👏 👏 👏 👏

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.

2 participants