Skip to content

Incorrect behavior of SimplifyForeachToArrayFilterRector #7592

@Wohlie

Description

@Wohlie

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.org/demo/3ae03387-fdc2-469b-9e0c-b0d888a155f1

<?php

class DataFilter
{
    public function filter(array $data): array
    {
        $filteredData = [];
        foreach ($data as $key => $value) {
            if ($key) {
                $filteredData[$key] = $value;
            }
        }

        return $filteredData;
    }
}

Responsible rules

  • SimplifyForeachToArrayFilterRector

Expected Behavior

The refactored code miss the definition of $key for the callback, as second parameter.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions