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

Incorrect behavior of UnderscoreToCamelCaseLocalVariableNameRector #5715

Closed
sanmai opened this issue Mar 1, 2021 · 2 comments · Fixed by #5718
Closed

Incorrect behavior of UnderscoreToCamelCaseLocalVariableNameRector #5715

sanmai opened this issue Mar 1, 2021 · 2 comments · Fixed by #5718
Labels

Comments

@sanmai
Copy link
Contributor

sanmai commented Mar 1, 2021

Bug Report

Subject Details
Rector version last dev-master
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.org/demo/34fcf41f-eef0-4ff3-aad9-ce6bf3abfbb1

<?php

final class DoNotOverwriteExistingVariables
{
    public function foo()
    {
       $foo_bar = 4;
       $fooBar = 2;

       $testExample = 5;
       $test_example = 7;
    }
}

Diff:

     public function foo()
     {
-       $foo_bar = 4;
+       $fooBar = 4;
        $fooBar = 2;
 
        $testExample = 5;
-       $test_example = 7;
+       $testExample = 7;
     }

Responsible rules

  • UnderscoreToCamelCaseLocalVariableNameRector

Expected Behavior

Rector should not rename variables if there's another variable with the same name in current scope. Otherwise put, this example should not be changed at all.

@sanmai sanmai added the bug label Mar 1, 2021
@TomasVotruba
Copy link
Member

Thank you for your report and demo link!

Could you send a failing test case in a pull-request, so we have it covered in Rector?
Here is step by step tutorial how to add it: https://github.com/rectorphp/rector/blob/master/docs/how_to_add_test_for_rector_rule.md

@sanmai
Copy link
Contributor Author

sanmai commented Mar 1, 2021

Sure thing #5716

samsonasik added a commit that referenced this issue Mar 1, 2021
TomasVotruba pushed a commit that referenced this issue Mar 1, 2021
…in next and previous assign variable (#5718)

* Fixture for UnderscoreToCamelCaseLocalVariableNameRector

See #5715

* try

* fixture

* Closes #5716 Fixes #5715

* final touch

* [ci-review] Rector Rectify

Co-authored-by: Alexey Kopytko <alexey@kopytko.com>
Co-authored-by: kaizen-ci <info@kaizen-ci.org>
TomasVotruba added a commit that referenced this issue Mar 12, 2024
rectorphp/rector-src@c390eab Skip mixed in ParamTypeByMethodCallTypeRector as not specific (#5715)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants