Skip to content

Bug with NewlineBeforeNewAssignSetRector #8991

@guideloince

Description

@guideloince

Bug Report

Subject Details
Rector version 2.0.6

Hi People,

I discovered a problem during my development.

Indeed, on the rule "NewlineBeforeNewAssignSetRector", I had a very strange case, and I only reproduced it within a class. Here is the initial code:

class Foo
{
    public function bar(): void
    {
        $bar         = new \stdClass();
        $bar->barFoo = false;

        $barFoo           = new \stdClass();
        $barFoo->tokenize = false;
    }
}

Rector tries to add a line after the second class declaration.

class Foo
{
    public function bar(): void
    {
        $bar         = new \stdClass();
        $bar->barFoo = false;

        $barFoo           = new \stdClass();
        $barFoo->tokenize = false;
    }
}

By trying several different cases it turns out that my property must have the same name as my next variable. In my case ->barFoo and $barFoo.

Minimal PHP Code Causing Issue

demo

Expected Behaviour

For me is a bug in rector but i'm not sure !

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