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 SimplifyIfElseToTernaryRector + ChangeIfElseValueAssignToEarlyReturnRector #1710

Merged
merged 8 commits into from
Jan 21, 2022

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Jan 21, 2022

Given the following code:

final class UseOnReturnAfterIfElseAssign
{
    public static function classToArray($data, $primaryKey = null, string $dateFormat = 'datetime'): array
    {
        if (method_exists($data, 'toRawArray')) {
            $properties = $data->toRawArray();
        } else {
            $properties = (array) $data;
        }

        return $properties;
    }
}

It currently produce:

-        if (method_exists($data, 'toRawArray')) {
-            $properties = $data->toRawArray();
-        } else {
-            $properties = (array) $data;
-        }
-
-        return $properties;
+        $properties = method_exists($data, 'toRawArray') ? $data->toRawArray() : (array) $data;

which return is removed, which should be kept.

This PR try to Fixes rectorphp/rector#6955

@samsonasik samsonasik force-pushed the use-on-return-after-ternary branch 2 times, most recently from b1c4f11 to 2c94fb9 Compare January 21, 2022 14:28
@samsonasik samsonasik marked this pull request as draft January 21, 2022 14:31
@samsonasik samsonasik marked this pull request as ready for review January 21, 2022 15:10
@samsonasik
Copy link
Member Author

Fixed 🎉

@samsonasik
Copy link
Member Author

/cc @MGatner

@samsonasik
Copy link
Member Author

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

@samsonasik
Copy link
Member Author

I am merging it ;)

@samsonasik samsonasik merged commit 369c2f7 into main Jan 21, 2022
@samsonasik samsonasik deleted the use-on-return-after-ternary branch January 21, 2022 23:32
@TomasVotruba
Copy link
Member

👍

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