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

[PHPStan 1.11] Init PHPStanServicesFactory to load PHPStan ContainerFactory() early on LazyContainerFactory #5897

Closed
wants to merge 4 commits into from

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented May 19, 2024

Real Fixes rectorphp/rector#8641

@simonschaufi based on @ondrejmirtes suggestion on rectorphp/rector#8641 (comment) , it seems on PHPStan 1.11, the PHPStan ContainerFactory need to be loaded early so :

TypeCombinator::addNull()

can be used in the rector config.

Before (Internal error.)

➜  typo3-rector git:(bb) vendor/bin/rector process src/Helper --config templates/rector.php --dry-run --ansi --clear-cache

                                                                                                                        
 [ERROR] Internal error.                                                                                                                                                                                                                  

After (working ok)

➜  typo3-rector git:(bb) vendor/bin/rector process src/Helper --config templates/rector.php --dry-run --ansi --clear-cache
 4/4 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

                                                                                                                        
 [OK] Rector is done!                                                                                      

@samsonasik samsonasik marked this pull request as draft May 19, 2024 10:46
@samsonasik
Copy link
Member Author

Hm.., it strange that when I create e2e test, it show diff when using UnionType, but not show the diff when using TypeCombinator

With TypeCombinator

➜  type-combinator-in-config git:(phpstan-service-factory-init) ✗ php ../e2eTestRunner.php 
 3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%[OK] Rector is done!%  

With UnionType

➜  type-combinator-in-config git:(phpstan-service-factory-init) ✗ php ../e2eTestRunner.php
 3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%1 file with changes
===================

1) src/NullWithObjectType.php:3

    ---------- begin diff ----------
@@ @@

 class NullWithObjectType implements FolderInterface
 {
-    public function create(string $fileName)
+    public function create(string $fileName): ?\App\FileInterface
     {

     }
    ----------- end diff -----------

Applied rules:
 * AddReturnTypeDeclarationRector


 [OK] 1 file would have changed (dry-run) by Rector%  

@samsonasik
Copy link
Member Author

I added e2e test for it 2aebf23

@samsonasik
Copy link
Member Author

samsonasik commented May 19, 2024

It seems due to overlapped config, and it loaded later, but because the rector config (cache path, etc) need to be loaded before it, it can't be flipped.

It seems using UnionType is the way to go for now.

Closing for now.

@samsonasik samsonasik closed this May 19, 2024
@samsonasik samsonasik deleted the phpstan-service-factory-init branch May 19, 2024 11:11
@simonschaufi
Copy link
Contributor

Thank you for your attempt to fix it.

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