Skip to content

Incorrect behavior of ForeachItemsAssignToEmptyArrayToAssignRector #7966

Description

@mpesari

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/a3014949-2478-48ef-bb13-be09ff14abc4

<?php

final class DemoFile
{
    private function getOtherValues(): array {
        return [];
    }

    public function getValues(bool $condition): array
    {
        $values = [];
        
        if ($condition) {
            $values[] = 'hello';
        }
        
        // Append other values to list.
        // FIXME: Rule changes code to overwrite 'hello'.
        foreach ($this->getOtherValues() as $value) {
            $values[] = $value;
        }
        
        return $values;
    }
}

Responsible rules

  • ForeachItemsAssignToEmptyArrayToAssignRector

Expected Behavior

I guess in this case Rector should do nothing

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions