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

Get ready for PHPStan 2.0 #8815

Closed
Tracked by #96
ondrejmirtes opened this issue Sep 4, 2024 · 53 comments
Closed
Tracked by #96

Get ready for PHPStan 2.0 #8815

ondrejmirtes opened this issue Sep 4, 2024 · 53 comments
Labels

Comments

@ondrejmirtes
Copy link
Contributor

Feature Request

Hi, I just started working on PHPStan 2.0 which will come with PHP-Parser 5. These are early days of the development, but you can already require phpstan/phpstan:^2.0 (with minimum-stability dev) and start working on making Rector compatible.

There will be more backward compatibility breaks coming in the next few months as I work towards to release, but you can already start getting rector-src ready for Rector 2.0 which will require PHPStan 2.0.

Please keep this issue open so we can discuss the next major PHPStan version. I'd also appreciate any feedback from your side. Thanks. 🤞

@TomasVotruba
Copy link
Member

TomasVotruba commented Sep 4, 2024

Sounds good 👍

We'll give this a priority by the end of the year and do upgrade of both PHPStan 2 and php-parser 5 at once.

@ondrejmirtes
Copy link
Contributor Author

We're now in the release candidate period phpstan/phpstan#11816

@samsonasik
Copy link
Member

rector phpstan's extensions seems need to have compatible to phpstan 2 first:

  Problem 1
    - Root composer.json requires rector/type-perfect ^0.1.6 -> satisfiable by rector/type-perfect[0.1.6, 0.1.7, 0.1.8].
    - rector/type-perfect[0.1.6, ..., 0.1.8] require phpstan/phpstan ^1.11 -> found phpstan/phpstan[1.11.0, ..., 1.12.x-dev] but it conflicts with your root composer.json require (^2.0).
  Problem 2
    - Root composer.json requires symplify/phpstan-extensions ^11.4 -> satisfiable by symplify/phpstan-extensions[11.4.0, 11.4.1, 11.4.2, 11.4.3].
    - symplify/phpstan-extensions[11.4.0, ..., 11.4.3] require phpstan/phpstan ^1.10 -> found phpstan/phpstan[1.10.0, ..., 1.12.x-dev] but it conflicts with your root composer.json require (^2.0).
  Problem 3
    - Root composer.json requires symplify/phpstan-rules ^13.0 -> satisfiable by symplify/phpstan-rules[13.0.0, 13.0.1].
    - symplify/phpstan-rules[13.0.0, ..., 13.0.1] require phpstan/phpstan ^1.10.30 -> found phpstan/phpstan[1.10.30, ..., 1.12.x-dev] but it conflicts with your root composer.json require (^2.0).
  Problem 4
    - Root composer.json requires tomasvotruba/unused-public ^0.3.10 -> satisfiable by tomasvotruba/unused-public[0.3.10, 0.3.11].
    - tomasvotruba/unused-public[0.3.10, ..., 0.3.11] require phpstan/phpstan ^1.10.19 -> found phpstan/phpstan[1.10.19, ..., 1.12.x-dev] but it conflicts with your root composer.json require (^2.0).
  Problem 5
    - Root composer.json requires phpstan/phpstan-phpunit ^1.4 -> satisfiable by phpstan/phpstan-phpunit[1.4.0, 1.4.x-dev].
    - phpstan/phpstan-phpunit 1.4.0 requires phpstan/phpstan ^1.11 -> found phpstan/phpstan[1.11.0, ..., 1.12.x-dev] but it conflicts with your root composer.json require (^2.0).
    - phpstan/phpstan-phpunit 1.4.x-dev requires phpstan/phpstan ^1.12 -> found phpstan/phpstan[1.12.0, ..., 1.12.x-dev] but it conflicts with your root composer.json require (^2.0).

@szepeviktor
Copy link
Contributor

@TomasVotruba Today is 11.11. Do you plan to make Rector PHPStan 2 compatible this week?

@samsonasik
Copy link
Member

First step: symplify/phpstan-extensions#12

@TomasVotruba
Copy link
Member

@szepeviktor Depends how many only-in-Rector BC breaks we'll have to deal with. We use lot of internal code, so it might be a challange.

@samsonasik Could you look into it? rector/rector first, so we can keep it focused on single repository

@samsonasik
Copy link
Member

@TomasVotruba sure, phpstan 2 require php-parser 5 so it will need revisit my old PR:

to be reincorporated ;)

@canvural
Copy link

I think best way to start is to enable bleeding edge and maybe install phpstan-deprecation-rules and start fixing stuff that pops up. We don't need to require 2.0 for that.

@ondrejmirtes
Copy link
Contributor Author

Exactly, as the upgrading guide says!

@samsonasik
Copy link
Member

sure, see rectorphp/rector-src#6415

@carlos-granados
Copy link

I created this PR for tomasvotruba/unused-public TomasVotruba/unused-public#135, probably complementary to TomasVotruba/unused-public#134

@carlos-granados
Copy link

Another PR for tomasvotruba/type-coverage TomasVotruba/type-coverage#46, complementary to TomasVotruba/type-coverage#45

@samsonasik
Copy link
Member

I am trying to install phpstan 2 and php-parser 5

the php-parser is patched, and currently got error on phpstan service:

44) Rector\Tests\Issues\AutoImport\AutoImportTest::test with data set #43 ('/Users/samsonasik/www/rector-...hp.inc')
_PHPStan_2a200beec\Nette\DI\ServiceCreationException: Service 'rectorParser' (type of PHPStan\Parser\RichParser): Unable to pass specified arguments to RichParser::__construct().

@carlos-granados
Copy link

I would prefer a solution that would allow us to keep the getDefinition() function if it already exists as I like how it shows the functionality of the rule. We don't use #[\Override]

@samsonasik
Copy link
Member

samsonasik commented Nov 23, 2024

@carlos-granados add getRuleDefinition() method will still works, just remove the #[\Override] attribute if exists as it may conflict with real dependency vs rector scoped dependency.

@samsonasik
Copy link
Member

new PR to avoid conflict with real dependency of symplify/rule-doc-generator

@g5bot
Copy link

g5bot commented Nov 23, 2024

Just tried rector/dev-main on our project. Works like a charm. Migrated to v2 without any problems! Good work @samsonasik
st-universe/core#1937

@TomasVotruba
Copy link
Member

TomasVotruba commented Nov 23, 2024

@carlos-granados

@TomasVotruba does this mean that when we upgrade to Rector 2.0 we need to remove our getDefinition() functions or can they remain in place even if they are no longer needed?

For 99 % use cases, they should be removed. The code snippets should be part of tests, if you have any.

If you use them in some own tooling to generate documentation, you can implement Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface on your rules.

@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

After @samsonasik's latest fix, both Rector and PHPStan work 🎉

@FabianKoestring
Copy link

After @samsonasik's latest fix, both Rector and PHPStan work 🎉

Everything is working for me too! 👍👌

@bobdivinity
Copy link

bobdivinity commented Nov 27, 2024

I just find out a new issue with Rector on my code :

image

The match() usage seems to not be handled as expected. I had this issue with boolean, string or enum expressions.
I have fixed my code with upwarding the condition before calling the match() method.

Also, I don't understand why I havce this error on parts of my code whereas other usages of match() method are working well

Here the stack trace :

 [ERROR] Could not process                                                      
         "/var/www/html/app/Models/CommercialReportPackage.php" file, due to:   
         "System error: "Call to undefined method                               
         Rector\PhpParser\Printer\BetterStandardPrinter::pPHPStan_Node_AlwaysRem
         emberedExpr()"                                                         
                                                                                
         Stack trace:                                                           
         #0                                                                     
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(580): PhpParser\PrettyPrinterAbstract->pFallback()       
         #1                                                                     
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(98
         ): PhpParser\PrettyPrinterAbstract->p()                                
         #2                                                                     
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(688):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->p()                    
         #3                                                                     
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(98
         ): PhpParser\PrettyPrinterAbstract->p()                                
         #4                                                                     
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(688):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->p()                    
         #5                                                                     
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(98
         ): PhpParser\PrettyPrinterAbstract->p()                                
         #6                                                                     
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(688):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->p()                    
         #7                                                                     
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(98
         ): PhpParser\PrettyPrinterAbstract->p()                                
         #8                                                                     
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(878):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->p()                    
         #9                                                                     
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(17
         1): PhpParser\PrettyPrinterAbstract->pArray()                          
         #10                                                                    
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(616):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->pArray()               
         #11                                                                    
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(98
         ): PhpParser\PrettyPrinterAbstract->p()                                
         #12                                                                    
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(688):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->p()                    
         #13                                                                    
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(98
         ): PhpParser\PrettyPrinterAbstract->p()                                
         #14                                                                    
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(688):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->p()                    
         #15                                                                    
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(98
         ): PhpParser\PrettyPrinterAbstract->p()                                
         #16                                                                    
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(878):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->p()                    
         #17                                                                    
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(17
         1): PhpParser\PrettyPrinterAbstract->pArray()                          
         #18                                                                    
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(616):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->pArray()               
         #19                                                                    
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(98
         ): PhpParser\PrettyPrinterAbstract->p()                                
         #20                                                                    
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(878):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->p()                    
         #21                                                                    
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(17
         1): PhpParser\PrettyPrinterAbstract->pArray()                          
         #22                                                                    
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(616):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->pArray()               
         #23                                                                    
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(98
         ): PhpParser\PrettyPrinterAbstract->p()                                
         #24                                                                    
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(878):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->p()                    
         #25                                                                    
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(17
         1): PhpParser\PrettyPrinterAbstract->pArray()                          
         #26                                                                    
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(616):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->pArray()               
         #27                                                                    
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(98
         ): PhpParser\PrettyPrinterAbstract->p()                                
         #28                                                                    
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(878):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->p()                    
         #29                                                                    
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(17
         1): PhpParser\PrettyPrinterAbstract->pArray()                          
         #30                                                                    
         vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinte
         rAbstract.php(545):                                                    
         Rector\PhpParser\Printer\BetterStandardPrinter->pArray()               
         #31                                                                    
         vendor/rector/rector/src/PhpParser/Printer/BetterStandardPrinter.php(53
         ): PhpParser\PrettyPrinterAbstract->printFormatPreserving()            
         #32 vendor/rector/rector/src/Application/FileProcessor.php(159):       
         Rector\PhpParser\Printer\BetterStandardPrinter->printFormatPreserving( 
         )                                                                      
         #33 vendor/rector/rector/src/Application/FileProcessor.php(110):       
         Rector\Application\FileProcessor->printFile()                          
         #34                                                                    
         vendor/rector/rector/src/Application/ApplicationFileProcessor.php(174):
         Rector\Application\FileProcessor->processFile()                        
         #35                                                                    
         vendor/rector/rector/src/Application/ApplicationFileProcessor.php(151):
         Rector\Application\ApplicationFileProcessor->processFile()             
         #36                                                                    
         vendor/rector/rector/src/Application/ApplicationFileProcessor.php(128):
         Rector\Application\ApplicationFileProcessor->processFiles()            
         #37 vendor/rector/rector/src/Console/Command/ProcessCommand.php(150):  
         Rector\Application\ApplicationFileProcessor->run()                     
         #38                                                                    
         vendor/rector/rector/vendor/symfony/console/Command/Command.php(285):  
         Rector\Console\Command\ProcessCommand->execute()                       
         #39 vendor/rector/rector/vendor/symfony/console/Application.php(900):  
         RectorPrefix202411\Symfony\Component\Console\Command\Command->run()    
         #40 vendor/rector/rector/vendor/symfony/console/Application.php(279):  
         RectorPrefix202411\Symfony\Component\Console\Application->doRunCommand 
         ()                                                                     
         #41 vendor/rector/rector/src/Console/ConsoleApplication.php(53):       
         RectorPrefix202411\Symfony\Component\Console\Application->doRun()      
         #42 vendor/rector/rector/vendor/symfony/console/Application.php(162):  
         Rector\Console\ConsoleApplication->doRun()                             
         #43 vendor/rector/rector/bin/rector.php(130):                          
         RectorPrefix202411\Symfony\Component\Console\Application->run()        
         #44 vendor/rector/rector/bin/rector(5): require_once('...')            
         #45 vendor/bin/rector(119): include('...')                             
         #46 {main}". On line: 557   

@ondrejmirtes
Copy link
Contributor Author

Class Rector\PhpParser\Printer\BetterStandardPrinter should extended PHPStan's Printer which has this method.

@samsonasik
Copy link
Member

@bobdivinity that seems due to:

Let's revert.

@samsonasik
Copy link
Member

@bobdivinity please update and try once more

@bobdivinity
Copy link

it's perfect ! Thanks buddy

@arderyp
Copy link

arderyp commented Nov 27, 2024

no issue for me either using dev-main

@TomasVotruba
Copy link
Member

TomasVotruba commented Nov 27, 2024

Thank you all for feedbacks 🙏 Time to move testing to next phase... Here we go 🎉 🎉 🎉

https://github.com/rectorphp/rector/releases/tag/2.0.0-rc1

@antoniovj1
Copy link

antoniovj1 commented Nov 29, 2024

Tested on a project with PHP 8.3 / Symfony 7.2 with approximately 25k files, and everything looks perfect 💪

@chescos
Copy link

chescos commented Dec 3, 2024

Is there an expected timeframe for the release of Rector 2 already?

@carlos-granados
Copy link

@chescos I think it is expected on 12/12

@TomasVotruba
Copy link
Member

@chescos I think it is expected on 12/12

Yes 👍 In the meantime, you can bump to 2.0-rc1

#8815 (comment)

@TomasVotruba
Copy link
Member

TomasVotruba commented Dec 3, 2024

The rc2 has just been tagged → https://github.com/rectorphp/rector-src/releases/tag/2.0.0-rc2 🔥🔥🔥

@ariaieboy
Copy link

version 2.0.0 tagged 🤔
https://github.com/rectorphp/rector-src/releases/tag/2.0.0

@samsonasik
Copy link
Member

Closing as implemented.

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

No branches or pull requests