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

RemoveAlwaysTrueIfConditionRector with array_push is buggy #8860

Open
jg-development opened this issue Oct 14, 2024 · 1 comment
Open

RemoveAlwaysTrueIfConditionRector with array_push is buggy #8860

jg-development opened this issue Oct 14, 2024 · 1 comment
Labels

Comments

@jg-development
Copy link

jg-development commented Oct 14, 2024

Bug Report

Subject Details
Rector version 1.2.5

RemoveAlwaysTrueIfConditionRector removes a correct if statement.
Code is quite ugly. It seems the problem is with:

  1. array_push .... with "$outerList[$id][] = [];" insetad of "array_push($outerList[$id], []);" it works
  2. an array with at least 2 foreach iterations are needed => with "$idList = [1];" it works
    private function demo(): void
    {
        $outerList = [];
        $idList = [1, 2];

        foreach ($idList as $id) {
            $outerList[$id] = [];
            array_push($outerList[$id], []);
        }

        $resultSet = [];

        foreach ($outerList as $key => $outerElement) {
            $result = false;

            foreach ($outerElement as $innerElement) {
                $result = true;
            }

            if (!$result) {
                array_push($resultSet, $key);
            }
        }
    }

rector remove the if statement:

-            if (!$result) {
-                array_push($resultSet, $key);
-            }
+            array_push($resultSet, $key);

Expected Behaviour

Rule should not be executed/change code

@samsonasik
Copy link
Member

samsonasik commented Oct 14, 2024

We use phpstan to detect type, on phpstan, it is detected as falsy, I think it should be reported there on phpstan side, see https://phpstan.org/r/73565769-6b97-48b7-8b52-e3b8883a5961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants