Skip to content

Enforcing spacing in method chaining #3331

Open
@tpalts

Description

@tpalts

I'm looking for a rule that enforces newline and spacing in method chaining. When chaining is used and there is a line break anywhere in the chain:

  • ALL chained methods should begin on a new line
  • with the arrow operator beginning that line
  • and each line being indented +1 compared to the first line.

Question:
What combination of rules could I use to achieve this, if any?

Examples:

Allow:

$x = Model::query()->where('x', 1)->where('y', 2)->get();
$x = Model::query()
    ->where('x', 1)
    ->where('y', 2)
    ->get();

Don't allow:

$x = Model::query()->where('x', 1)
->where('y', 2)->get();

$x = Model::query()
->where('x', 1)
->where('y', 2)
->get();

$x = Model::query()->
    where('x', 1)->
    where('y', 2)->
    get();

Thanks!

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