Skip to content

withPhpSets(php84: true) breaks valid (new (expr))->method() syntax #9182

@SandraCHC

Description

@SandraCHC

Bug Report

Subject Details
Rector version 2.0.16

Minimal PHP Code Causing Issue

I can't reproduce it in the demo. I use Laravel 11 and https://github.com/driftingly/rector-laravel/. But if I use a minimal config without rector-laravel, I get the same issue.

Minimal config

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/app',
    ])
    ->withPhpSets(php84: true);

Code:

    public static function getGlobalSearchEloquentQuery(): Builder
    {
        //...

        return (new (static::getModel()))->newQuery()
            ->orderByDesc('received_at');
    }

The change:

-        return (new (static::getModel()))->newQuery()
+        return new (static::getModel())->newQuery()

But only if I use

->withPhpSets();
//or
->withPhpSets(php84: true);

But I have no problems with this code

->withPhpSets(php83: true);

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