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

[Naming][Php56] Do not add default value init for renamed variable from param on RenameParamToMatchTypeRector+AddDefaultValueForUndefinedVariableRector #1716

Merged
merged 4 commits into from
Jan 24, 2022

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Jan 24, 2022

Given the following code:

use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode;

class Fixture
{
    public function hasTruePseudoType(BracketsAwareUnionTypeNode $type): bool
    {
        $unionTypes = $type->types;

        foreach ($unionTypes as $unionType) {}
    }
}

It currently produce define init null value which invalid as variable is from renamed param:

     public function hasTruePseudoType(BracketsAwareUnionTypeNode $bracketsAwareUnionTypeNode): bool
     {
+        $bracketsAwareUnionTypeNode = null;
         $unionTypes = $bracketsAwareUnionTypeNode->types;

Applied rules:

Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector;
Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;

@samsonasik
Copy link
Member Author

Fixed 🎉

@samsonasik
Copy link
Member Author

samsonasik commented Jan 24, 2022

I am merging it, the functionality was removed at #1697 that was still working due to direct use of renamed parameter, while if it is assigned back on this PR use case, it will failure.

This patch rolled back the detection functionality with the assigned back use case.

@samsonasik samsonasik merged commit 386c97b into main Jan 24, 2022
@samsonasik samsonasik deleted the do-not-init-renamed-from-param branch January 24, 2022 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant