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

[CodeQuality][EarlyReturn] Handle ChangeOrIfReturnToEarlyReturnRector + ChangeAndIfToEarlyReturnRector + DateTimeToDateTimeInterfaceRector #794

Merged
merged 9 commits into from
Aug 31, 2021

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Aug 31, 2021

Given the following code:

class AndNextOr
{
    public function run($a, $b, $c, $d)
    {
        if ($a && $b || $c) {
            return null;
        }

        $a = 1;
        $b = 2;

        if ($b > $a) {
            return null;
        }

        $d = 1;

        return;
    }
}

Currently produce repetitive ifs and and returns:

+        if (!$a) {
+            return;
+        }
+        if (!$b) {
+            return;
+        }
+        if (!$a) {
+            return;
+        }
+        if (!$b) {
+            return;
+        }
+        if (!$a) {
+            return;
+        }
+        if (!$b) {
+            return;
+        }
+        if (!$a) {
+            return;
+        }
+        if (!$b) {
+            return;
+        }
+        if (!$a) {
+            return;
+        }
+        if (!$b) {
+            return;
+        }
+        if (!$a) {
+            return;
+        }
+        if (!$b) {
+            return;
+        }
+        if (!$a) {
+            return;
+        }
+        if (!$b) {
+            return;
+        }
+        if (!$a) {
+            return;
+        }
+        if (!$b) {
+            return;
+        }
         if ($a && $b) {
             return null;
         }
+        return null;
+        return null;
+        return null;
+        return null;
+        return null;
+        return null;
+        return null;
+        return null;
         if ($c) {
             return null;
         }

Used rules:

Rector\CodeQuality\Rector\ClassMethod\DateTimeToDateTimeInterfaceRector;
Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector;
Rector\EarlyReturn\Rector\If_\ChangeOrIfReturnToEarlyReturnRector;

@samsonasik
Copy link
Member Author

Fixed 🎉

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

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