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

[DeadCode][EarlyReturn] Handle RemoveUnusedVariableAssignRector + RemoveAlwaysElseRector #1277

Merged
merged 18 commits into from
Nov 20, 2021

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Nov 20, 2021

Given the following code:

final class Fixture
{
    public function run(Request $request)
    {
        $path = $request->get('path', null);
        $url  = $request->get('url', null);

        if (null !== $path) {
            return response()->file($path);
        } elseif (null !== $url) {
            return response()->getFile($url);
        }

        throw new \Exception('Error');
    }
}

It produce:

-        $path = $request->get('path', null);
+        $request->get('path', null);

which should not.

Applied rules:

Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector;
Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;

Fixes rectorphp/rector#6819

@samsonasik
Copy link
Member Author

Fixed 🎉

@samsonasik samsonasik force-pushed the hanlde-remove-unuesd-variable-always-else branch 3 times, most recently from 8480337 to 7a5d065 Compare November 20, 2021 10:48
@samsonasik
Copy link
Member Author

@TomasVotruba it fixed 🎉 , the rector-doctrine package tests error is unrelated.

@samsonasik samsonasik force-pushed the hanlde-remove-unuesd-variable-always-else branch from 34740af to b6cca31 Compare November 20, 2021 12:43
@samsonasik
Copy link
Member Author

rebased.

@samsonasik
Copy link
Member Author

@TomasVotruba using p5 on paratest seems cause error again after rebase:

https://github.com/rectorphp/rector-src/runs/4273392519?check_suite_focus=true#step:5:64

In WorkerCrashedException.php line 36:
                                                                               
  The command "'/home/runner/work/rector-src/rector-src/vendor/phpunit/phpuni  
  t/phpunit' '--configuration' '/home/runner/work/rector-src/rector-src/phpun  
  it.xml' '--no-logging' '--no-coverage' '--printer' 'ParaTest\Runners\PHPUni  
  t\Worker\NullPhpunitPrinter' '--log-junit' '/tmp/PT_ta1J0d' '/home/runner/w  
  ork/rector-src/rector-src/rules-tests/TypeDeclaration/Rector/Property/Typed  
  PropertyFromStrictGetterMethodReturnTypeRector/TypedPropertyFromStrictGette  
  rMethodReturnTypeRectorTest.php'" failed.                                    
                                                                               
  Exit Code: 137(Kill (terminate immediately))   

@samsonasik samsonasik force-pushed the hanlde-remove-unuesd-variable-always-else branch from e466269 to e4e0212 Compare November 20, 2021 13:05
@samsonasik
Copy link
Member Author

@TomasVotruba using p3 on parallel tests seems solve it 🎉

All checks have passed 🎉 it is ready for review.

@samsonasik
Copy link
Member Author

I am merging it ;)

@samsonasik samsonasik merged commit bc5462b into main Nov 20, 2021
@samsonasik samsonasik deleted the hanlde-remove-unuesd-variable-always-else branch November 20, 2021 13:25
@cavo789
Copy link
Contributor

cavo789 commented Nov 20, 2021

Just incredible 👌

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