Skip to content

NestedFuncCallsToPipeOperatorRector breaks spread operator in input #9710

@annadamm-check24

Description

@annadamm-check24

Bug Report

Subject Details
Rector version 2.3.9

When the input into a function uses the spread operator, the NestedFuncCallsToPipeOperatorRector breaks the code.

Minimal PHP Code Causing Issue

https://getrector.com/demo/fd1ebd94-1d07-4327-8b99-98dbbb506f80
this results in Warning: Array to string conversion.

Expected Behaviour

// input code
$arrayOfArrays = [['a'], ['a'], ['b']];
$merged = array_unique(array_merge(...$arrayOfArrays));

var_dump($merged); // ['a', 'b']

// this is what rector does
$merged = $arrayOfArrays
    |> array_merge(...) // results in no change, instead of arrays being merged together as in original
    |> array_unique(...); // warning 
var_dump($merged); // ->different! [['a']]

// this is what rector should do
$merged = array_merge(...$arrayOfArrays)
 |> array_unique(...);
var_dump($merged); // -> same as original code: ['a', 'b']

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