vscode-phpfmt icon indicating copy to clipboard operation
vscode-phpfmt copied to clipboard

Inconsistent Brace Alignment with `phpfmt.psr2: false` for Certain Method Return Types

Open ferhado opened this issue 1 year ago • 1 comments

I am experiencing a formatting inconsistency in the phpfmt formatter when the phpfmt.psr2 setting is set to false. Specifically, the formatter does not automatically align the opening braces { on the same line as the method signature for certain return types, though it maintains the brace position if manually adjusted.

Steps to Reproduce

  1. Set the phpfmt.psr2 configuration to false.
  2. Apply phpfmt formatting to a PHP class with methods having different return types.
  3. Observe the position of the opening brace in relation to the method signatures.

Current Behavior

With phpfmt.psr2 set to false, the formatter does not automatically place the opening brace on the same line for some method return types:

class ExampleClass {
  // Not automatically formatted correctly
  public function setCreator(?User $creator): static
  {
    $this->creator = $creator;

    return $this;
  }

  // Also not automatically formatted correctly
  public function getCreatedAt(): ?\DateTimeImmutable
  {
    return $this->createdAt;
  }
}

However, if the braces are manually placed on the same line, the formatter does not move them:

class ExampleClass {
  // Manually corrected format is maintained
  public function setCreator(?User $creator): static {
    $this->creator = $creator;

    return $this;
  }
}

Expected Behavior

The formatter should automatically place the opening brace on the same line as the method signature for all methods:

class ExampleClass {
  public function setCreator(?User $creator): static {
    $this->creator = $creator;

    return $this;
  }

  public function getCreatedAt(): ?\DateTimeImmutable {
    return $this->createdAt;
  }
}

ferhado avatar Nov 22 '23 22:11 ferhado