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

[e2e] handle multiple classes with anonymous class on MultipleClassFileToPsr4ClassesRector file removed #3253

Merged
merged 10 commits into from
Dec 25, 2022

Conversation

samsonasik
Copy link
Member

Given the following code:

final class DemoFile
{
    public function run()
    {
        new class {};
    }
}

On configuration:

<?php

declare (strict_types=1);

use Rector\Config\RectorConfig;
use Rector\PSR4\Rector\Namespace_\MultipleClassFileToPsr4ClassesRector;

return static function (RectorConfig $rectorConfig) : void {
    $rectorConfig->rule(MultipleClassFileToPsr4ClassesRector::class);
};

It cause crash :

➜  multiple-class-psr4 git:(e2e-handle-multiple-class-psr4-anonymous) php ../e2eTestRunner.php 
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%! [NOTE] File "./multiple-class-psr4/src/WithAnonymousClass.php" will be added

 ! [NOTE] File
 !        "./multiple-class-psr4/src/AnonymousClass803f48395af26ad9858c7b66bbbe9c19.p
 !        hp" will be added

 [WARNING] File "src/WithAnonymousClass.php" will be removed

Ref https://getrector.org/demo/d6b959e8-3007-4c95-bc92-eb0421236a4c

It only reproducible with e2e test due to on WorkerRunner usage:

$this->removedAndAddedFilesProcessor->run($configuration);

Fixes rectorphp/rector#7695

@samsonasik samsonasik force-pushed the e2e-handle-multiple-class-psr4-anonymous branch 2 times, most recently from 736537f to 02b1998 Compare December 25, 2022 05:12
@samsonasik samsonasik force-pushed the e2e-handle-multiple-class-psr4-anonymous branch from 02b1998 to ecf8024 Compare December 25, 2022 05:13
@samsonasik
Copy link
Member Author

@samsonasik
Copy link
Member Author

Fixed 🎉 with verify anonymous class via ClassAnalyzer->isAnonymousClass() cf463f7

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I think it is ready 🎉

@samsonasik
Copy link
Member Author

I also add handling for match and no match class with file 1b65a04 , the diffing will need improvement, but that will require different PR :)

Comment on lines +30 to +36
-class ClassMatchFileName implements SomeInterface
-{
-}
-
-interface SomeInterface
-{
-}
Copy link
Member Author

Choose a reason for hiding this comment

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

This diff require improvement as it actually changed to:

+class ClassMatchFileName implements \App\SomeInterface
+{
+}

when not using --dry-run, but that will need to be in separate PR for improvement :)

@samsonasik
Copy link
Member Author

Finally 🎉 🎉 🎉 All checks have passed 🎉 @TomasVotruba I think it is ready.

@TomasVotruba TomasVotruba merged commit 9a0938d into main Dec 25, 2022
@TomasVotruba TomasVotruba deleted the e2e-handle-multiple-class-psr4-anonymous branch December 25, 2022 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants