Skip to content

RemoveAlwaysTrueIfConditionRector with array_push is buggy #8860

@jg-development

Description

@jg-development

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions